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

go/types, types2: provide better error message for short variable declarations #43087

Closed
griesemer opened this issue Dec 9, 2020 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 9, 2020

Given

var a int
a, b, b := 1, 2, 3
_ = a
_ = b

The compiler reports: b repeated on left side of :=.
types2 (go tool compile -G) reports: b redeclared in this block.

The compiler error message seems better because it's actually ok to "redeclare" a variable (here: a) with a short variable declaration.

cc: @findleyr

@griesemer griesemer added this to the Go1.17 milestone Dec 9, 2020
@griesemer griesemer self-assigned this Dec 9, 2020
@griesemer griesemer changed the title types2: provide better error message for short variable errors types2: provide better error message for short variable declarations Dec 9, 2020
@griesemer griesemer changed the title types2: provide better error message for short variable declarations go/types, types2: provide better error message for short variable declarations Apr 21, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Apr 21, 2021

Change https://golang.org/cl/312170 mentions this issue: cmd/compile/internal/types2: better errors for invalid short var decls

Loading

@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Apr 21, 2021

cc: @findleyr

Loading

gopherbot pushed a commit that referenced this issue Apr 22, 2021
- rewrite Checker.shortVarDecl core loop for clarity
- match compiler error messages (#43087)
- don't allow multiple identical redeclarations (#45652)

For #43087.
For #45652.

Change-Id: I8c3329a553aa104d7853fbaea8b88049bc9b3b88
Reviewed-on: https://go-review.googlesource.com/c/go/+/312170
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@griesemer griesemer removed this from the Go1.17 milestone Apr 28, 2021
@griesemer griesemer added this to the Go1.18 milestone Apr 28, 2021
@findleyr
Copy link
Contributor

@findleyr findleyr commented Apr 29, 2021

This was resolved by the port to go/types: https://golang.org/cl/314629.

Loading

@findleyr findleyr closed this Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants