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

Line Breaks Should Not Be Allowed in Function Definitions #18090

Closed
kylieCat opened this issue Nov 29, 2016 · 2 comments
Closed

Line Breaks Should Not Be Allowed in Function Definitions #18090

kylieCat opened this issue Nov 29, 2016 · 2 comments

Comments

@kylieCat
Copy link

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

go version go1.6.3 darwin/amd64 (also on the playground)

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/ian/repos/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

According to the language spec defined here: https://golang.org/ref/spec#Lexical_elements

comments act like spaces. This also seems to be true in function definitions as seen here: https://play.golang.org/p/mJIRoAXM3u

This is also true in the creation of go routines seen here: https://play.golang.org/p/3ew1e917sC

It is possible to completely replace spaces with comments in function signatures as seen in this abomination: https://play.golang.org/p/oZsc2uMjk7

What did you expect to see?

At the very least this should generate some kind of style warning and ideally an error along the lines of Expected IDENT following func.... That last example should absolutely not compile.

What did you see instead?

All examples above will compile and run just fine. No warnings or errors are generated for the sins you have just committed.

@griesemer
Copy link
Contributor

This is working as intended per the spec.

@griesemer
Copy link
Contributor

@im-auld Go follows the tradition of any other language that is not line oriented: With the notable exception of automatic semicolon insertion, how you break your lines doesn't matter for the meaning of a program.

@golang golang locked and limited conversation to collaborators Nov 29, 2017
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