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

Golang grammar for constants #31207

Closed
ancaemanuel opened this issue Apr 2, 2019 · 5 comments
Closed

Golang grammar for constants #31207

ancaemanuel opened this issue Apr 2, 2019 · 5 comments

Comments

@ancaemanuel
Copy link

See this:
https://play.golang.org/p/50l_XzHNSiS

How it is possible to have this parsed: "-+-+-+-1" ?
I think it is an error on the parser side, or some more...

@go101
Copy link

go101 commented Apr 2, 2019

Why shouldn't it be parsed? -+-+-+-1 is equivalent to -(+(-(+(-(+(-1)))))).

@go101
Copy link

go101 commented Apr 2, 2019

Similarly,

var x int
var y = *&*&*&*&*&x // y == x

@ancaemanuel
Copy link
Author

@go101 in what language did you see that behaviour ?

@ancaemanuel
Copy link
Author

If we think math, that is simple to parse. But we are in other environment and we need to define very explicit what is ok.

@ianlancetaylor
Copy link
Contributor

@ancaemanuel I'm going to close this issue because the language spec clearly accepts these kind of expressions, and the compiler is doing the right thing per the language spec. If you have questions about this I suggest that you use a forum rather than the issue tracker; see https://golang.org/wiki/Questions . Thanks.

@golang golang locked and limited conversation to collaborators Apr 1, 2020
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

4 participants