aboutsummaryrefslogtreecommitdiff
path: root/test/switch.go
diff options
context:
space:
mode:
authorRémy Oudompheng <oudomphe@phare.normalesup.org>2012-08-03 21:47:26 +0200
committerRémy Oudompheng <oudomphe@phare.normalesup.org>2012-08-03 21:47:26 +0200
commitf4f1ba2b1ebb76d4277cd775215ccd12994ffb40 (patch)
tree487bb7df55ec24a0071305933de2d3250a5606a3 /test/switch.go
parent728f19131919734e473e3de425abb966b45b13f8 (diff)
downloadgo-f4f1ba2b1ebb76d4277cd775215ccd12994ffb40.tar.gz
go-f4f1ba2b1ebb76d4277cd775215ccd12994ffb40.zip
cmd/gc: accept switches on comparable arrays.
The compiler is incorrectly rejecting switches on arrays of comparable types. It also doesn't catch incomparable structs when typechecking the switch, leading to unreadable errors during typechecking of the generated code. Fixes #3894. R=rsc CC=gobot, golang-dev, r, remy https://golang.org/cl/6442074
Diffstat (limited to 'test/switch.go')
-rw-r--r--test/switch.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/switch.go b/test/switch.go
index 09bf4341a0..a4242f2571 100644
--- a/test/switch.go
+++ b/test/switch.go
@@ -284,6 +284,38 @@ func main() {
default:
}
+ // switch on interface.
+ switch i := interface{}("hello"); i {
+ case 42:
+ assert(false, `i should be "hello"`)
+ case "hello":
+ assert(true, "hello")
+ default:
+ assert(false, `i should be "hello"`)
+ }
+
+ // switch on array.
+ switch ar := [3]int{1, 2, 3}; ar {
+ case [3]int{1,2,3}:
+ assert(true, "[1 2 3]")
+ case [3]int{4,5,6}:
+ assert(false, "ar should be [1 2 3]")
+ default:
+ assert(false, "ar should be [1 2 3]")
+ }
+
+ // switch on channel
+ switch c1, c2 := make(chan int), make(chan int); c1 {
+ case nil:
+ assert(false, "c1 did not match itself")
+ case c2:
+ assert(false, "c1 did not match itself")
+ case c1:
+ assert(true, "chan")
+ default:
+ assert(false, "c1 did not match itself")
+ }
+
i := 0
switch x := 5; {
case i < x: