In the following example, the var err declared in main() will be flagged as unused variable.
However, in the switch syntax it it used correctly.
If you look at the screenshots, it reveals how the shorthand assignment from withing the case statement
will take over as the one that declares the variable for the remaining of the code execution while in the switch statement.
package main
import "fmt"
func Demo() error {
return fmt.Errorf("err")
}
func main() {
var err error
switch {
case 1==2:
err := Demo()
panic(err)
default:
err = Demo()
panic(err)
}
//panic(err)
}


Thank you.