-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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 for a bad rune value, eg. '\xe4\xb8\x96' #20343
Comments
For reference,
We could mimic |
I'd be satisfied with "illegal rune literal". One message, terse, accurate. |
As an aside ... |
I apologise for not understanding this, but why add it to Go1.10 milestone? Didn't that happened years ago? |
I don't think there is. I know Rust has something like that; and I agree that it could be nice to have something similar (even though Go is a simpler language and error messages usually are easy to understand; I rarely see people puzzled by a compiler error when programming in Go).
I agree. You could ask for this on their mailing list. I don't think it's "straightforward", though. Doing this (and doing it well) will require a fair amount of effort.
The dot in the versioning number is not a decimal point, i.e. The next go version will be go1.9, and then we'll have go1.10. I can't assign this issue to the 1.9 milestone because the go1.9 development phase is finished (we're now in a code freeze); so this will be likely considered for go1.10 (unless someone decides that this is critical and needs to be fixed for go1.9). |
Thank you for your very swift, clear and useful responses. I'll think about asking on the mailing list. When I do, I have a small, but hopefully useful, additional idea. I'd understood the 'dot' in the version is not a decimal point. It seems a very low-priority to have version and milestone names align. I imagine retaining flexibility to have them be different probably significantly outweighs any small gains. |
Marking for 1.9 - easy enough to fix. |
I'm going to close this. The 1.9 compiler already produces a nice error message. For
we get
That is, this is fixed in the latest tools. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?golang.org goplayground (1.8 I believe)
What operating system and processor architecture are you using (
go env
)?I am using go playground from Firefox.
However for completeness:
GOARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
Firefox 53.0.2 (64-bit)
What did you do?
https://play.golang.org/p/NtvSPO4xx7
What did you expect to see?
An error message like:
"Badly formed Rune" or "Bad rune value" maybe even
"runes with values larger than 255, 0xFF, can't be defined using multiple \xhh values"
What did you see instead?
tmp/sandbox523565836/main.go:5: missing '
tmp/sandbox523565836/main.go:5: illegal character U+005C '\'
tmp/sandbox523565836/main.go:5: syntax error: unexpected xb8 at end of statement
tmp/sandbox523565836/main.go:5: newline in character literal
Issue Explanation/Justification
I think the Go compilers error messages are unnecessarily unhelpful or confusing.
The source doesn't look like there is a "missing ' ", it looks like there are a matching pair of single quotes.
The character U+005C '\' is legal in rune values, so that seems confusing.
In this example, the value xb8 is apparently in the middle of the rune, and so "syntax error: unexpected xb8 at end of statement" seems confusing.
The line doesn't look like there is a "newline in character literal".
A plausible behaviour might be to 'collect' all the characters up to and including an unescaped closing single quote (on the same line, and before a '//' comment mark), and treat all of those characters as part of the bad rune value.
The text was updated successfully, but these errors were encountered: