Skip to content

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

@CodaFi

Description

@CodaFi
Previous ID SR-5337
Radar None
Original Reporter @CodaFi
Type Improvement
Additional Detail from JIRA
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions