-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.closuresFeature: closuresFeature: closurescompilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsFeature: expressionsgood first issueGood for newcomersGood for newcomersparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parser
Description
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 }
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.closuresFeature: closuresFeature: closurescompilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsFeature: expressionsgood first issueGood for newcomersGood for newcomersparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parser