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
Assignees

Comments

@ALTree
Copy link
Member

@ALTree 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 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

@griesemer griesemer commented Aug 14, 2021

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 ].

Loading

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

@gopherbot gopherbot commented Aug 15, 2021

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

Loading

@gopherbot gopherbot closed this in 6ed9463 Aug 15, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Aug 15, 2021

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

Loading

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants