mirror of
https://github.com/golang/go
synced 2024-11-22 03:34:40 -07:00
type switches: test for pathological case
R=rsc, r CC=golang-dev https://golang.org/cl/4894057
This commit is contained in:
parent
82189f654d
commit
fd897ffc68
@ -18,11 +18,27 @@ func whatis(x interface{}) string {
|
|||||||
return "Reader1"
|
return "Reader1"
|
||||||
case io.Reader: // ERROR "duplicate"
|
case io.Reader: // ERROR "duplicate"
|
||||||
return "Reader2"
|
return "Reader2"
|
||||||
case interface { r(); w() }:
|
case interface {
|
||||||
|
r()
|
||||||
|
w()
|
||||||
|
}:
|
||||||
return "rw"
|
return "rw"
|
||||||
case interface { w(); r() }: // ERROR "duplicate"
|
case interface {
|
||||||
|
w()
|
||||||
|
r()
|
||||||
|
}: // ERROR "duplicate"
|
||||||
return "wr"
|
return "wr"
|
||||||
|
|
||||||
}
|
}
|
||||||
return ""
|
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)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user