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

cmd/compile: less helpful error message for invalid array types #51145

Closed
Merovius opened this issue Feb 11, 2022 · 6 comments
Closed

cmd/compile: less helpful error message for invalid array types #51145

Merovius opened this issue Feb 11, 2022 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Merovius
Copy link
Contributor

Originally reported on golang-nuts.

It seems the go 1.18 type checker provides less helpful error messages in some cases of invalid array type declarations. For this declaration:

type A [float64]int

The go 1.17 compiler prints (playground link):

./prog.go:3:8: invalid array bound float64
./prog.go:3:9: type float64 is not an expression

While the go 1.18 compiler prints (playground link):

./prog.go:3:9: float64 (type) is not an expression

Note that it omits the "invalid array bound float64" message. This seems like a regression to me.

@KZiemian
Copy link

Thank you @Merovius for taking initiative. I hesitated about posting it myself, because I guess that problem error message "invalid array bound float64" was possible, when compiler know that "[something]" means definition of array. But now it can also mean definition of type parameter and compiler can't/doesn't decide which case it is.

Of course, I may be wrong.

@ianlancetaylor
Copy link
Contributor

CC @griesemer @findleyr

@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 11, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Feb 11, 2022
@griesemer griesemer self-assigned this Feb 11, 2022
@griesemer griesemer modified the milestones: Go1.19, Go1.18 Feb 11, 2022
@griesemer
Copy link
Contributor

This happens to be trivial to fix and it is not invasive. CL forthcoming.

@gopherbot
Copy link

Change https://go.dev/cl/385255 mentions this issue: go/types, types2: better error message for invalid array length

@gopherbot
Copy link

Change https://go.dev/cl/439476 mentions this issue: go/types, types2: better error for generic type decl. with missing constraint

@gopherbot
Copy link

Change https://go.dev/cl/439559 mentions this issue: go/types, types2: better error for generic type decl. with missing constraint

gopherbot pushed a commit that referenced this issue Oct 10, 2022
…nstraint

If a generic type declaration is missing a constraint, syntactically
it is an array type declaration with an undefined array length.
Mention the possibility of a missing constraint in the error message
for the undefined array length.

For #56064.
For #55961.
For #51145.

Change-Id: Ic161aeda9ea44faa8aa3bf3e9d62b3b13a95d4c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/439559
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
romaindoumenc pushed a commit to TroutSoftware/go that referenced this issue Nov 3, 2022
…nstraint

If a generic type declaration is missing a constraint, syntactically
it is an array type declaration with an undefined array length.
Mention the possibility of a missing constraint in the error message
for the undefined array length.

For golang#56064.
For golang#55961.
For golang#51145.

Change-Id: Ic161aeda9ea44faa8aa3bf3e9d62b3b13a95d4c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/439559
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
@golang golang locked and limited conversation to collaborators Oct 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants