Incorrect ineffectual assignment in switch
Closed this issue · 2 comments
glooms commented
I found a false ineffectual assignment in a case similar to this:
package main
import (
"fmt"
)
func main() {
var a int
switch n := -1; {
case n == -1:
n += 1
fallthrough
case n == 0:
a = 10
}
fmt.Println(a)
}
It says that n += 1
is ineffectual when it is very much effectual. Without it a
is 0
, with it it's 10
.
Same example on go playground here.
(Also, thanks for good linting in general, very useful for catching bugs. :) )
gordonklaus commented
I tried your playground example and got 10
both with and without n += 1
. Which is to be expected; fallthrough
always passes control to the next case block regardless of the next case condition.
glooms commented
Ah! Didn't know that, but it makes sense. I guess there was a bug in my code after-all then ^^
Apologies, and thanks! :)
I'll close this issue