Constant_declarations spec


(mohammed) #1

Hello,

https://golang.org/ref/spec#Constant_declarations

According to the grammar defined in the link above, the statement ‘const toto’ could compile (or in other words, is idiomatic) . This is wrong and thanks God the Golang indeed throw a compilation error.

Regards,


(Johan Dahl) #2

It is valid if it comes after another declaration. See these examples

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

and

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


(mohammed) #3

Yes, indeed.

But, like I said, the statement “const toto” is considered valid based on the grammar, which is wrong in practice.

https://play.golang.org/p/Il6Rk-SqzaS

This snippet is not working, but the constant_declartions section says it’s valid.