Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6994] Bad diagnostic with unrecognized enum case #49542

Closed
NachoSoto opened this issue Feb 13, 2018 · 2 comments
Closed

[SR-6994] Bad diagnostic with unrecognized enum case #49542

NachoSoto opened this issue Feb 13, 2018 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis

Comments

@NachoSoto
Copy link
Contributor

Previous ID SR-6994
Radar rdar://problem/37537338
Original Reporter @NachoSoto
Type Bug
Status Resolved
Resolution Done
Environment
  • Swift version 4.1 (swiftlang-902.0.38 clang-902.0.31)

  • Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee @NachoSoto
Priority Medium

md5: ebd3b2edbb1414b07de21ce24f775969

Issue Description:

struct S<T, E> {
    init(t: T) {}
    init(e: E) {}
}

enum E {
    case e1
    case e2
}

func f() -> S<Int, E> {
    // This should produce something like "E.e3 is not defined, did you mean .e2?"
    // Instead, Swift 4.0.3: error: cannot convert return expression of type 'S<_, _>' to return type 'S<Int, E>'
    // And Swift 4.1: error: type of expression is ambiguous without more context.
    return S(e: .e3)
}

This diagnostic is wrong no matter what's wrong with the passed value. For example, getting the label of a case wrong fails in the same way:

struct S<T, E> {
    init(t: T) {}
    init(e: E) {}
}

enum E {
    case e1
    case e2(label: String)
}

func f() -> S<Int, E> {
    // This should produce a fixit to correct "wrongLabel" to "label"
    // Instead, Swift 4.0.3: error: cannot convert return expression of type 'S<_, _>' to return type 'S<Int, E>'
    // And Swift 4.1: error: type of expression is ambiguous without more context.
    return S(e: .e2(wrongLabel: "test"))
}
@belkadan
Copy link
Contributor

@swift-ci create

@xedin
Copy link
Member

xedin commented Feb 5, 2020

Sorry it took us a while to get to this point but starting from 5.2 we produce better diagnostics for both cases:

 error: type 'E' has no member 'e3'
  return S(e: .e3)
              ~^~

and

incorrect argument label in call (have 'wrongLabel:', expected 'label:')
      return S(e: .e2(wrongLabel: "test"))
                     ^~~~~~~~~~~
                      label

@NachoSoto If possible, please use the latest nightly snapshot of master/5.2 to verify and close.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants