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

Comments

Projects
None yet
7 participants
@StScAllen
Copy link

commented Mar 7, 2017

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

This comment has been minimized.

Copy link

commented Mar 7, 2017

@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

This comment has been minimized.

Copy link

commented Mar 7, 2017

Can be closed because of a non issue.

@dhananjay92 dhananjay92 closed this Mar 7, 2017

@ALTree

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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 label Mar 7, 2017

@ALTree ALTree added this to the Go1.9Maybe milestone Mar 7, 2017

@klingtnet

This comment has been minimized.

Copy link

commented Mar 7, 2017

@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

This comment has been minimized.

Copy link
Contributor

commented Mar 7, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2017

What's a column?

@klingtnet

This comment has been minimized.

Copy link

commented Mar 8, 2017

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

@ALTree

This comment has been minimized.

Copy link
Member

commented Mar 8, 2017

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

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Mar 9, 2017

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.

@griesemer griesemer closed this Mar 9, 2017

@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.
You can’t perform that action at this time.