swiftlang/swift

[SR-5337] Improve diagnostic for 'var' in parameter position

Open

#47,911 opened on Jun 29, 2017

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Swift (69,989 stars) (10,719 forks)batch import
compilerdiagnostics qualitygood first issueimprovement

Description

Previous ID SR-5337
Radar None
Original Reporter @CodaFi
Type Improvement
Votes 1
Component/s Compiler
Labels Improvement, DiagnosticsQoI, StarterBug
Assignee None
Priority Medium

md5: df452a4dc52959caff3a154681f76513

Issue Description:

For code that looks like this

func foo(inout x : Int) {}

or

func foo(_ f : (Int) -> Void) {}

foo { (var x) in
  
}

We used to offer to remove the errant 'var' specifier and extract it into a variable in the body of the function/closure. This diagnostic necessitated a compromise in our modeling of parameter declarations that I have removed. In its place, it would be nice to have a diagnostic of similar quality.

Some ideas would be to redo the old diagnostic, but by first "enqueueing" it then emitting the variable into the body of the function/closure after we parse the opening brace/'in' after a parameter list. Or we could simply do what we do for 'inout' and remove the 'var' specifier then assume the user actually wanted 'inout', etc.

Contributor guide