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: incorrect error message on unclosed [ in map indexing #47704

Closed
ALTree opened this issue Aug 14, 2021 · 3 comments
Closed

cmd/compile: incorrect error message on unclosed [ in map indexing #47704

ALTree opened this issue Aug 14, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@ALTree
Copy link
Member

ALTree commented Aug 14, 2021

go version go1.16.5 linux/amd64
go version devel go1.18-a632b433a1 Fri Aug 13 19:30:04 2021 +0200 linux/amd64
package p

func f(m map[int]int) int {
	return m[0
		]
}
$ go build test.go
# command-line-arguments
./test.go:4:12: syntax error: unexpected newline, expecting :

The expecting : part of the error message is plainly wrong, as there's no way to get a program that compiles by putting a : there.

go/types correctly reports expected ']', found newline.

cc @griesemer

@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 14, 2021
@ALTree ALTree changed the title cmd/compile: incorrect error message on unclosed ] in map indexing cmd/compile: incorrect error message on unclosed [ in map indexing Aug 14, 2021
@griesemer
Copy link
Contributor

Note that is a syntax error and not a type-checking error, so the compiler doesn't know the type of m. In this case the parser assumes that the incomplete m[0 was going to be a slice expression and thus expected a : (slices tend to be more common than maps). The error should probably be syntax error: unexpected newline, expecting : or ].

@griesemer griesemer self-assigned this Aug 14, 2021
@gopherbot
Copy link

Change https://golang.org/cl/342369 mentions this issue: cmd/compile/internal/syntax: better error message for index syntax error

@gopherbot
Copy link

Change https://golang.org/cl/342370 mentions this issue: cmd/compile/internal/types2: better error message for index syntax error (follow-up)

gopherbot pushed a commit that referenced this issue Aug 15, 2021
…ror (follow-up)

For #47704.

Change-Id: I09e6f638df0cd456a20a3b68ab55c47bb5b1f555
Reviewed-on: https://go-review.googlesource.com/c/go/+/342370
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Jun 23, 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

3 participants