Advertising

The current language spec says that omitting the switch expression is
equivalent to writing `true`. If you actually write `true`, then,
following the usual rules for untyped constant expressions, it will
receive the type `bool`, and you would get the same mismatched type
error. You will see a similar case if you write `switch 0` and try to
compare with a named version of `int`. So the compiler is following
the language spec as currently written.
We could change the language spec to say that omitting the switch
expression is not equivalent to writing `true`, but instead, as you
suggest, compares each case to an untyped `true` value. I think the
main argument against that is that it makes the spec slightly more
complicated while bringing very little benefit. You could write it up
as a language change proposal if you like.
Ian
--
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.