aboutsummaryrefslogtreecommitdiff
path: root/test/typeswitch2.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-08-19 09:31:50 -0700
committerRobert Griesemer <gri@golang.org>2011-08-19 09:31:50 -0700
commitfd897ffc68022f436e328acfe47807e0b5ec18dc (patch)
treeff7dc234693201a41e898ec91888e190324ea397 /test/typeswitch2.go
parent82189f654df7f3032f27a764ec8ce662f68764c1 (diff)
downloadgo-fd897ffc68022f436e328acfe47807e0b5ec18dc.tar.gz
go-fd897ffc68022f436e328acfe47807e0b5ec18dc.zip
type switches: test for pathological case
R=rsc, r CC=golang-dev https://golang.org/cl/4894057
Diffstat (limited to 'test/typeswitch2.go')
-rw-r--r--test/typeswitch2.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/test/typeswitch2.go b/test/typeswitch2.go
index f8fe396eae..57c5a18ab2 100644
--- a/test/typeswitch2.go
+++ b/test/typeswitch2.go
@@ -18,11 +18,27 @@ func whatis(x interface{}) string {
return "Reader1"
case io.Reader: // ERROR "duplicate"
return "Reader2"
- case interface { r(); w() }:
+ case interface {
+ r()
+ w()
+ }:
return "rw"
- case interface { w(); r() }: // ERROR "duplicate"
+ case interface {
+ w()
+ r()
+ }: // ERROR "duplicate"
return "wr"
-
+
}
return ""
}
+
+func notused(x interface{}) {
+ // The first t is in a different scope than the 2nd t; it cannot
+ // be accessed (=> declared and not used error); but it is legal
+ // to declare it.
+ switch t := 0; t := x.(type) { // ERROR "declared and not used"
+ case int:
+ _ = t // this is using the t of "t := x.(type)"
+ }
+}