Skip to content

[SR-11724] Provide a diagnostic when a closure parameter is declared with type sugar #54133

@CodaFi

Description

@CodaFi
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.closuresFeature: closurescompilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexpressionsFeature: expressionsgood first issueGood for newcomersparserArea → compiler: The legacy C++ parser

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions