That's an interesting case. It does seem to me that if you have an interface-typed value in a no-condition switch statement then it's quite likely to be an accident. However, AFAICS this issue applies only to the empty interface type, so ISTM that it is unlikely to be common.
It's too late for Go 1, as this would be a backwardly incompatible change. It is possible that it might be worth adding as a go vet check though. It would add weight if a search of a large corpus of Go code found a good number of places where this form was used in error. If it *was* a rule that the type must be bool, then it would be simple enough to work around the restriction if you really did want an interface in there - just add "== true". On Sat, 21 Apr 2018 2:29 pm , <b97...@gmail.com> wrote: > var someInterfaceValue interface{} > switch { > case someInterfaceValue: // proposal: compile error: non-bool used as > condition > case someInterfaceValue == true: // OK > } > > Sometimes carefulness is just not enough. > One may type a wrong variable as the case condition, or a incomplete > condition. > Why is this special? Because it's commonly used. > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > On 21 Apr 2018 14:29, <b97...@gmail.com> wrote: var someInterfaceValue interface{} switch { case someInterfaceValue: // proposal: compile error: non-bool used as condition case someInterfaceValue == true: // OK } Sometimes carefulness is just not enough. One may type a wrong variable as the case condition, or a incomplete condition. Why is this special? Because it's commonly used. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.