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

go/scanner: reuse of SEMICOLON token for new lines allows new lines in places where semicolons are required #19711

Closed
erizocosmico opened this issue Mar 25, 2017 · 1 comment

Comments

@erizocosmico
Copy link

erizocosmico commented Mar 25, 2017

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

go version go1.7.5 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build324900564=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

If we look at the spec, for example, of the if statement, we can see it explicitly says a semicolon is required to separate the statement from the expression. In practice, a newline is also correct as can be seen in the following link.

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

Same happens with for init; cond; incr { statements and, well, every other place that requires a semicolon.

What did you expect to see?

That newlines are not correct in places where ; are required.

What did you see instead?

They are.

I assume this is because go/scanner uses the token type token.SEMICOLON for both semicolons and new lines. Maybe this is working as expected, but then the spec should say that either a semicolon or a newline are possible delimiters.

@griesemer
Copy link
Contributor

If you look at the spec, you will also see that each statement in a statement list needs to be explicitly terminated by a semicolon (https://golang.org/ref/spec#Block) - yet we don't need to write them.

The reason is that semicolons are inserted automatically ( https://golang.org/ref/spec#Semicolons ).

This is working as intended.

@golang golang locked and limited conversation to collaborators Mar 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants