-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Parse] Provide a diagnostic when a closure parameter is declared with type sugar #28315
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
[Parse] Provide a diagnostic when a closure parameter is declared with type sugar #28315
Conversation
@CodaFi A few questions regarding the PR:
|
There’s a third concern here which is that this change is source-breaking. I am aware of at least one client that uses |
I don't think that this change is source-breaking. My understanding is that Please let me know if I misunderstood. I can take it up to swift-evolution if it's source-breaking. |
Remember that overload resolution is diagnosing this situation today. The non-overloaded case sometimes compiles. The test only contains the overloaded case. |
Got it, I didn't think about that. Cool, so I will start a discussion on swift-evolution soon. |
Just one tiny little nit and I think this should be good to take. Thanks! |
@CodaFi: I am unable to create an example where the non-overloaded case would compile. Could you give it a try? My example: struct Bar {}
struct Foo {
func registerCallback(_ callback: @escaping (Bar?) -> Void) {}
}
Foo().registerCallback { (Bar?) in } Fails with: /tmp/Hello.swift:9:30: error: expected ',' separator
Foo().registerCallback { (Bar?) in }
^
,
/tmp/Hello.swift:9:30: error: expected parameter name followed by ':'
Foo().registerCallback { (Bar?) in } |
Oh, sorry, let me try to expand here: The source break stems from the general fix to this bug, which is to make what is currently a warning in that test you just updated a hard error. There are known cases where type sugar in parameter position happens to compile, and the most egregious one I know of uses array sugar: https://swift.godbolt.org/z/gkqhCw. Even more distressingly, that one also accepts Getting this through the source compatibility suite was insufficient to catch users of this the last time I tried, so my general fear is that we'll regress again. We need to go to evolution to get an up-or-down vote on whether we should be allowed to ban this, which will give us a clearer picture of whether we need to go fixup the failing projects, or continue to warn about them until we add a new language version or whatever. |
@swift-ci please smoke test |
@swift-ci please test source compatibility |
Hm, these jobs never finished @swift-ci please smoke test |
@swift-ci please test source compatibility |
You got a bad builder on macOS @swift-ci please smoke test macOS platform |
⛵️ |
@CodaFi did you folks internally conclude to merge this feature ? Also, I am sorry I couldn’t spend enough time to create a Swift-evolution discussion around this. |
I merged here because we’ve passed the 5.2 rebranch date. If this breaks any more adopters then we’ll have time to fix them and assess the scope of the issue. We still need to go to evolution about the broader underlying issue. |
@CodaFi |
Closure parameters are not allowed to be shadow sugared types. This PR tries to provide an error diagnostic for the same.
Resolves #54133.