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 for a bad rune value, eg. '\xe4\xb8\x96' #20343

Closed
gbulmer opened this issue May 12, 2017 · 8 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@gbulmer
Copy link

gbulmer commented May 12, 2017

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.

@ALTree ALTree changed the title Confusing Go compiler error message for a bad rune value, eg. '\xe4\xb8\x96' cmd/compile: confusing error message for a bad rune value, eg. '\xe4\xb8\x96' May 13, 2017
@ALTree
Copy link
Member

ALTree commented May 13, 2017

For reference, go/types prints

runes.go:5:9: illegal rune literal

We could mimic go/types behaviour. I have no idea how much work would be needed, so leaving it to others to decide if it's worth it.

@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 13, 2017
@ALTree ALTree added this to the Go1.10 milestone May 13, 2017
@gbulmer
Copy link
Author

gbulmer commented May 13, 2017

I'd be satisfied with "illegal rune literal". One message, terse, accurate.

@gbulmer
Copy link
Author

gbulmer commented May 13, 2017

As an aside ...
Is their a 'place' explaining all of the Go compilers error messages? My search didn't find it.
It would be nice to have all Go compiler error messages along with a brief explanation of a possible cause of the error in a web-searchable place.
I paste error messages from software into a web browser's search box, but in this case it didn't find much help. Sometimes stackoverflow is helpful, but not in this case.
Explaining compiler error-messages might be a straightforward, well-bounded, activity to ask the Developer Experience Working Group to solve. The result could be helpful for new or occasional Go programmers, and so help them climb the learning curve more quickly and effectively.
Further, if the 'place' had some authority or evidence of good quality, it might be the 'go to' place.

@gbulmer
Copy link
Author

gbulmer commented May 13, 2017

I apologise for not understanding this, but why add it to Go1.10 milestone? Didn't that happened years ago?

@ALTree
Copy link
Member

ALTree commented May 13, 2017

Is their a 'place' explaining all of the Go compilers error messages

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

Explaining compiler error-messages might be a straightforward, well-bounded, activity to ask the Developer Experience Working Group to solve

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.

I apologise for not understanding this, but why add it to Go1.10 milestone? Didn't that happened years ago?

The dot in the versioning number is not a decimal point, i.e. 1.10 is not 1.1. The sequence goes 1.1, 1.2, ..., 1.9, 1.10, 1.11, etc...

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

@gbulmer
Copy link
Author

gbulmer commented May 13, 2017

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.
I hadn't known milestone names don't align with Go versions. So that is helpful to know.

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.

@griesemer griesemer self-assigned this May 15, 2017
@griesemer griesemer modified the milestones: Go1.9, Go1.10 May 15, 2017
@griesemer
Copy link
Contributor

Marking for 1.9 - easy enough to fix.

@ALTree ALTree added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels May 15, 2017
@griesemer
Copy link
Contributor

I'm going to close this. The 1.9 compiler already produces a nice error message. For

$ cat x.go
package main

func main() {
	r20 := '\xe4\xb8\x96'
}

we get

$ go tool compile x.go
x.go:4:9: invalid character literal (more than one character)

That is, this is fixed in the latest tools.
The go playground will be updated to 1.9 once 1.9 is released.

@golang golang locked and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants