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: broken := operator generates bizarre error #19440

Closed
StScAllen opened this issue Mar 7, 2017 · 11 comments
Closed

cmd/compile: broken := operator generates bizarre error #19440

StScAllen opened this issue Mar 7, 2017 · 11 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@StScAllen
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.3 windows/amd64

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\GoWork;C:\GoWork\src\github.com\user\character
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\all
st\AppData\Local\Temp\go-build641294366=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1

What did you do?

https://play.golang.org/p/Nk92HWr1YX

For loop generates error that opening { brace is missing. Rather than
informing user the := operator is severed.

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

unexpected token ':' on line 7
(or something like that)
Really anything but the missing { comment, as the brackets are all correct.

What did you see instead?

syntax error: missing { after for clause

@klingtnet
Copy link

@StScAllen := is not broken, your example contained a redundant space between the colon : and equal sign =. Here is a link to a working example.

PS: You can wrap multiple lines of code in triple backticks so it is rendered in a monospaced font.

@klingtnet
Copy link

Can be closed because of a non issue.

@ALTree
Copy link
Member

ALTree commented Mar 7, 2017

Why was this closed? The OP is reporting the fact that the error message that you get when you mis-type ":=" as ": =" is misleading. That's a valid complaint.

Also, I remember reading a similar issue in the past (about misleading errors related to for statements parsing).

@ALTree ALTree reopened this Mar 7, 2017
@ALTree
Copy link
Member

ALTree commented Mar 7, 2017

Ah, it was #17328. The typo is different, but the misleading message was the same: a not-very-informative "missing { after for clause".

@ALTree ALTree changed the title Broken := operator generates bizarre error cmd/compile: broken := operator generates bizarre error Mar 7, 2017
@ALTree
Copy link
Member

ALTree commented Mar 7, 2017

On tip, the error message is:

syntax error: unexpected :, expecting { after for clause

a little better (at least it mentions :).

Leaving for someone else to decide if improving the reported error for a broken : = is worth it.

@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 7, 2017
@ALTree ALTree added this to the Go1.9Maybe milestone Mar 7, 2017
@klingtnet
Copy link

@ALTree You're right I overlooked this sentence:

For loop generates error that opening { brace is missing. Rather than
informing user the := operator is severed.

@griesemer
Copy link
Contributor

I'll take a look - it's not hard to recognize this case, but it's unclear it's worth it. The better thing might be to print column/offset information in error messages (we do have that information now), as it would point much more clearly at the place where the error occurred (rather than just mentioning a line).

@griesemer griesemer self-assigned this Mar 7, 2017
@robpike
Copy link
Contributor

robpike commented Mar 8, 2017

What's a column?

@klingtnet
Copy link

I think with column he means the index/position in the line.

@ALTree
Copy link
Member

ALTree commented Mar 8, 2017

For more arguing about columns: #10324 (comment). :^)

@griesemer
Copy link
Contributor

At tip, the error reported is:

tmp.go:7: syntax error: unexpected :, expecting { after for clause

which is pretty clear. That is, this has been fixed as part of another issue.
Furthermore, once the compiler reports column information (#10324), the reported error is:

tmp.go:7:8: syntax error: unexpected :, expecting { after for clause

pin-pointing the offending token exactly. Once 1.9 is out, the playground will behave the same.

Closing as there's nothing else to do here.

@golang golang locked and limited conversation to collaborators Mar 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

7 participants