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

Open
go101 opened this issue Jun 15, 2023 · 3 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
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
@Nasfame
Copy link
Contributor

Nasfame commented Jun 15, 2023

By human reasoning and gofmt its pretty clear that the square brackets doesn't enclose constraints. Nearest reasoning is that there is typo in defining the slice!

So most plausible error should be syntax error: array length must be a constant

@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
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. generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Todo
Development

No branches or pull requests

6 participants