You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
./prog.go:8:9: 1 evaluated but not used
./prog.go:11:2: invalid case 1 in switch (mismatched types int and bool)
Some thoughts:
It seems to be interpreting the switch as having a simple statement "preamble" (the 1 expression) and missing a "switch value", which defaults to true, which is why it's complaining about int and bool not matching. Note that if you press the "Format" button in the Playground, it inserts a semicolon after the 1 in the "switch value" position.
It complains that 1 is evaluated but not used. This seems to be referring to the switch simple statement preamble. Isn't this also wrong? I read the language spec section for the switch statement, and there's nothing in there referring to a requirement about the statement being used. A SimpleStmt can indeed be an expression statement, according to the grammar there, if I understood correctly, so I'm confused where this is coming from. I thought maybe this is coming from the same place in the spec that forbids unused local variables, but the only place in the spec I could find that refers to that is "Implementation restriction: A compiler may make it illegal to declare a variable inside a function body if the variable is never used" in the Variable declarations section, which doesn't seem to apply to expression statements. Maybe I've missed or forgotten the relevant part of the spec?
The text was updated successfully, but these errors were encountered:
This is mostly working as intended, or at least working as specified. As the spec says, a multiline comment is replaced by a newline. Thus your code, as seen by the compiler, has a newline after the 1, which by the rules of semicolon insertion terminates the switch statement at that point.
The error messages are a little odd, but the program is not valid.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/o7TbBE3RD0h
What did you expect to see?
No errors.
What did you see instead?
Errors:
Some thoughts:
1
expression) and missing a "switch value", which defaults to true, which is why it's complaining about int and bool not matching. Note that if you press the "Format" button in the Playground, it inserts a semicolon after the 1 in the "switch value" position.The text was updated successfully, but these errors were encountered: