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-15077] Better error messages for enum cases as protocol witnesses #57403

Open
swift-ci opened this issue Aug 16, 2021 · 2 comments
Open

[SR-15077] Better error messages for enum cases as protocol witnesses #57403

swift-ci opened this issue Aug 16, 2021 · 2 comments
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-15077
Radar rdar://problem/82176920
Original Reporter EduardLev (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI
Assignee None
Priority Medium

md5: 99cf7e150879e216868128a0f9c3e048

Issue Description:

Enum cases can conform to protocol static func requirements. However, when the static func involves closures, the error messages produced by the compiler can seem confusing. Take this case:

enum MyEnum: MyProtocol { // Error: Type `MyEnum` does not conform to protocol `MyProtocol`
  case one(value: (Bool) -> Void) 
}
 
protocol MyProtocol { 
  static func one(value: (Bool) -> Void) -> Self 
}

For this, the compiler will show an error on `enum MyEnum` as seen above. If you apply Xcode's "fix it", you would get the following code generated, which leads to another error:

enum MyEnum: MyProtocol {
  static func one(value: (Bool) -> Void) -> MyEnum { // Error: Invalid redeclaration of one(value:)
    code...   
  }
  case one(value: (Bool) -> Void) 

However, the reason that `MyEnum` did not conform to `MyProtocol` was because the closure was not marked `@escaping` in the protocol requirements. Perhaps, the error message for this instance can be improved to notify the programmer of this condition.

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@theblixguy
Copy link
Collaborator

theblixguy commented Jul 30, 2022

It's not specific to this case BTW:

struct MyStruct: MyProtocol {
  static func one(value: @escaping (Bool) -> Void) -> Self { fatalError() }
}
 
protocol MyProtocol { 
  static func one(value: (Bool) -> Void) -> Self 
}

triggers the same error. I suppose we need to improve the type mismatch diagnostic to account for attributes as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement
Projects
None yet
Development

No branches or pull requests

3 participants