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-11724] Provide a diagnostic when a closure parameter is declared with type sugar #54133

CodaFi opened this issue Nov 6, 2019 · 2 comments


Copy link

@CodaFi CodaFi commented Nov 6, 2019

Previous ID SR-11724
Radar rdar://problem/56950572
Original Reporter @CodaFi
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, StarterBug
Assignee None
Priority Medium

md5: 48f0d1bec40f4cb6b0df056014613eb7

Issue Description:

Closure parameters are already allowed to shadow types. What they are not allowed to do is shadow sugared types, or attempt to destructure them:

struct Bar {}

struct Foo {
  func registerCallback(_ callback: @escaping ([Bar]) -> Void) {}
  func registerCallback(_ callback: @escaping ([String: Bar]) -> Void) {}
  func registerCallback(_ callback: @escaping (Bar?) -> Void) {}

Foo().registerCallback { ([Bar]) in }
Foo().registerCallback { ([String: Bar]) in }
Foo().registerCallback { (Bar?) in }

This emits a pile of diagnostics, and none of them are good. We should be able to catch this during Parse and emit a much better diagnostic. Ideally one that inserts what the user probably meant

Foo().registerCallback { (_: [Bar]) in }
Foo().registerCallback { (_: [String: Bar]) in }
Foo().registerCallback { (_: Bar?) in }
Copy link
Member Author

@CodaFi CodaFi commented Nov 6, 2019

@swift-ci create

Copy link
Member Author

@CodaFi CodaFi commented Nov 6, 2019

Tagging this as a starter bug, but it's kind of an open-ended intermediate bug. The parsing logic for ParamDecls is a mess. But we should at least be emitting some kind of diagnostic consistently when we come across these kinds of parameters. Today, it's up to overload resolution to make sure this is rejected, which is way too late.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant