-
Notifications
You must be signed in to change notification settings - Fork 769
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
Show warning, when overwriting variable #3674
Comments
Hi guettli, Based on the go spec,
In this case,
If I understand your quest, you are looking for a warning when you re-declare a variable in the inner block. In this case, show a warning in line 3 @findleyr to see if this is something worth implementing from the gopls side. |
@guettli redeclaring a variable in an inner scope is a pretty normal thing to do in Go. Given the Go spec and the language's approach to this situation I think an external linter is more appropriate than gopls itself issuing a warning for all inner scope redeclarations. That being said I think this particular scenario is well suited for go vet to the point where I'm almost surprised it isn't already a warning. I suggest submitting a proposal in the go repo to add a go vet analyzer that:
While I agree with the language designers that redeclaration in general should not be considered a problem, I've been tripped up by this specific scenario many times. |
@firelizzard18 thank you for your feedback I created an issue in the Go repo for that: golang/go#71555 |
Hi guettli I find this issue very similar to your request here. I wonder if this is something you are looking for. #270
I give it a try with function below and variable ![]() ![]() |
Is your feature request related to a problem? Please describe.
I wrote that code, and I did not understand why
path
was empty, althoughfindDev()
returns a non-empty path:Describe the solution you'd like
I would like to see a warning in vscode, when I overwrite a variable from the outer scope.
Describe alternatives you've considered
I could use external linters, but I think that should be available "out of the box".
The text was updated successfully, but these errors were encountered: