aboutsummaryrefslogtreecommitdiff
path: root/test/switch.go
diff options
context:
space:
mode:
authorRémy Oudompheng <oudomphe@phare.normalesup.org>2013-02-26 00:45:43 +0100
committerRémy Oudompheng <oudomphe@phare.normalesup.org>2013-02-26 00:45:43 +0100
commit71b3b460738decbce5f1797492eaa59b06d69687 (patch)
treeefb00a869a5948c4095f95e8f256faee46e0e23c /test/switch.go
parent9e66ee456210024ad05ba95f3b245cdc974aba43 (diff)
downloadgo-71b3b460738decbce5f1797492eaa59b06d69687.tar.gz
go-71b3b460738decbce5f1797492eaa59b06d69687.zip
cmd/gc: accept cases with same value but different types in switch.
Fixes #4781. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7365056
Diffstat (limited to 'test/switch.go')
-rw-r--r--test/switch.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/switch.go b/test/switch.go
index c6a0ebc74a..bcbde68e46 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}: