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-5337] Improve diagnostic for 'var' in parameter position #47911

Open
CodaFi opened this issue Jun 29, 2017 · 2 comments
Open

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

CodaFi opened this issue Jun 29, 2017 · 2 comments
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement

Comments

@CodaFi
Copy link
Member

CodaFi commented Jun 29, 2017

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.

@CodaFi
Copy link
Member Author

CodaFi commented Jun 29, 2017

For reference, this is the commit I removed it in.

@swift-ci
Copy link
Collaborator

Comment by Mike Choi (JIRA)

Just so it's clear, do we want the above closure to be diagnosed and fixed to become the following

foo { ( x ) in{{ var x = x }}{{}}}

if we can all agree on the fact that people who use var on a parameter doesn't mean to use inout?

@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
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers improvement
Projects
None yet
Development

No branches or pull requests

2 participants