]> Cypherpunks repositories - gostls13.git/commit
spec: document existing expression switch restrictions
authorRobert Griesemer <gri@golang.org>
Mon, 27 Jul 2015 20:30:16 +0000 (13:30 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 30 Jul 2015 23:11:20 +0000 (23:11 +0000)
commit2d9378c7f6dfbbe82d1bbd806093c2dfe57d7e17
tree622156a71807f759cf3060ebcfe4d2368d53a599
parentf4c775eb70f732000e5260214a1f6e100089a1b0
spec: document existing expression switch restrictions

The spec didn't specify several aspects of expression switches:

- The switch expression is evaluated exactly once.

- Switch expressions evaluating to an untyped value are converted
  to the respective default type before use.

- An (untyped) nil value is not permitted as expression switch
  value. (We could permit it relatively easily, but gc doesn't,
  and disallowing it is in symmetry with the rules for var decls
  without explicit type and untyped initializer expressions.)

- The comparison x == t between each case expression x and
  switch expression value t must be valid.

- (Some) duplicate constant case expressions are not permitted.

This change also clarifies the following issues:

 4524: mult. equal int const switch case values should be illegal
                                         -> spec issue fixed
 6398: switch w/ no value uses bool rather than untyped bool
                                         -> spec issue fixed
11578: allows duplicate switch cases     -> go/types bug
11667: int overflow in switch expression -> go/types bug
11668: use of untyped nil in switch      -> not a gc bug

Fixes #4524.
Fixes #6398.
Fixes #11668.

Change-Id: Iae4ab3e714575a5d11c92c9b8fbf027aa706b370
Reviewed-on: https://go-review.googlesource.com/12711
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
doc/go_spec.html