diff options
author | R?my Oudompheng <oudomphe@phare.normalesup.org> | 2013-02-26 00:45:43 +0100 |
---|---|---|
committer | R?my Oudompheng <oudomphe@phare.normalesup.org> | 2013-02-26 00:45:43 +0100 |
commit | 2478fe7369656ac5918244b61c20261a40bbcf28 (patch) | |
tree | 764226379012f7669b0a9e7ef4f8f30a2558a04e /test/switch.go | |
parent | d3668771286a97e056f402c39a47f577810b9a6c (diff) | |
download | go-2478fe7369656ac5918244b61c20261a40bbcf28.tar.gz |
cmd/gc: accept cases with same value but different types in switch.
Fixes issue 4781.
R=golang-dev, rsc
CC=golang-dev
https://codereview.appspot.com/7365056
Diffstat (limited to 'test/switch.go')
-rw-r--r-- | test/switch.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/switch.go b/test/switch.go index c6a0ebc74..bcbde68e4 100644 --- a/test/switch.go +++ b/test/switch.go @@ -305,6 +305,35 @@ func main() { assert(false, "i should be true") } + // switch on interface with constant cases differing by type. + // was rejected by compiler: see issue 4781 + type T int + type B bool + type F float64 + type S string + switch i := interface{}(float64(1.0)); i { + case nil: + assert(false, "i should be float64(1.0)") + case (*int)(nil): + assert(false, "i should be float64(1.0)") + case 1: + assert(false, "i should be float64(1.0)") + case T(1): + assert(false, "i should be float64(1.0)") + case F(1.0): + assert(false, "i should be float64(1.0)") + case 1.0: + assert(true, "true") + case "hello": + assert(false, "i should be float64(1.0)") + case S("hello"): + assert(false, "i should be float64(1.0)") + case true, B(false): + assert(false, "i should be float64(1.0)") + case false, B(true): + assert(false, "i should be float64(1.0)") + } + // switch on array. switch ar := [3]int{1, 2, 3}; ar { case [3]int{1, 2, 3}: |