aboutsummaryrefslogtreecommitdiff
path: root/test/switch3.go
diff options
context:
space:
mode:
authorLuuk van Dijk <lvd@golang.org>2011-11-09 10:58:53 +0100
committerLuuk van Dijk <lvd@golang.org>2011-11-09 10:58:53 +0100
commit13e92e4d7542ac65a7efb33778f752403c5ac014 (patch)
treeed9d3ba14020b4522d06ee75b2cf5892d06507e5 /test/switch3.go
parent820523d09186bd9c7078338803e41c8592158110 (diff)
downloadgo-13e92e4d7542ac65a7efb33778f752403c5ac014.tar.gz
go-13e92e4d7542ac65a7efb33778f752403c5ac014.zip
gc: Better typechecks and errors in switches.
Allow any type in switch on interface value. Statically check typeswitch early. Fixes #2423. Fixes #2424. R=rsc, dsymonds CC=golang-dev https://golang.org/cl/5339045
Diffstat (limited to 'test/switch3.go')
-rw-r--r--test/switch3.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/switch3.go b/test/switch3.go
new file mode 100644
index 0000000000..95ff6ec3c2
--- /dev/null
+++ b/test/switch3.go
@@ -0,0 +1,38 @@
+// errchk $G -e $D/$F.go
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+
+type I interface {
+ M()
+}
+
+func bad() {
+ var i I
+ var s string
+
+ switch i {
+ case s: // ERROR "mismatched types string and I"
+ }
+
+ switch s {
+ case i: // ERROR "mismatched types I and string"
+ }
+}
+
+func good() {
+ var i interface{}
+ var s string
+
+ switch i {
+ case s:
+ }
+
+ switch s {
+ case i:
+ }
+}