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: confusing error message when using an indexing expression as an array size #60812

Closed
go101 opened this issue Jun 15, 2023 · 5 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FixPending Issues that have a fix which has not yet been reviewed or submitted. generics Issue is related to generics
Milestone

Comments

@go101
Copy link

go101 commented Jun 15, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20.5 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

const S = "Go"

type T [S[0]]int // syntax error: type parameters must be named

func main() {}

What did you expect to see?

syntax error: array length must be a constant

or

syntax error: type constraint is incomplete

or

syntax error: either type constraint is incomplete or array length is not a constant

What did you see instead?

syntax error: type parameters must be named

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jun 15, 2023
@go101 go101 changed the title cmd/compile: impfect error message cmd/compile: imperfect error message Jun 15, 2023
@go101
Copy link
Author

go101 commented Jun 15, 2023

It looks the current implementation tries to think the only item in [] as a constraint.
Go 1.17.13 outputs non-constant array bound S[N] for the following code.
I prefer a message combining the two messages.

const S = "Go"

const N = 0

type T [S[N]]int

@ianlancetaylor
Copy link
Contributor

CC @griesemer

@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. generics Issue is related to generics labels Jun 19, 2023
@dmitshur dmitshur added this to the Backlog milestone Jun 19, 2023
@mknyszek mknyszek changed the title cmd/compile: imperfect error message cmd/compile: confusing error message when using an indexing expression as a constant Jun 28, 2023
@mknyszek mknyszek changed the title cmd/compile: confusing error message when using an indexing expression as a constant cmd/compile: confusing error message when using an indexing expression as an array size Jun 28, 2023
@griesemer griesemer modified the milestones: Backlog, Go1.22 Jun 28, 2023
@gopherbot
Copy link

Change https://go.dev/cl/538856 mentions this issue: cmd/compile/internal/syntax: better error messages for incorrect type parameter list

@gopherbot
Copy link

Change https://go.dev/cl/538858 mentions this issue: go/parser: better error messages for incorrect type parameter list

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. NeedsFix The path to resolution is known, but the work has not been done. labels Oct 31, 2023
gopherbot pushed a commit that referenced this issue Nov 2, 2023
This is a port of CL 538856 from the syntax parser to go/parser.
As part of the port, make more portions of parseParameterList
matching the equivalent paramList method (from the syntax parser).
As a result, this now also produces a better error message in cases
where the missing piece might not be a type parameter name but a
constraint (this fixes a TODO in a test).

Improve comments in the code and adjust the corresponding comments
in the syntax parser.

Change references to issues to use the format go.dev/issue/ddddd.

For #60812.

Change-Id: Ia243bd78161ed8543d3dc5deb20ca4a215c5b1e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/538858
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FixPending Issues that have a fix which has not yet been reviewed or submitted. generics Issue is related to generics
Projects
None yet
Development

No branches or pull requests

6 participants
@dmitshur @ianlancetaylor @griesemer @gopherbot @go101 and others