2012-02-16 21:51:04 -07:00
|
|
|
// errorcheck
|
2011-11-09 02:58:53 -07:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2012-02-23 17:48:19 -07:00
|
|
|
// Verify that erroneous type switches are caught be the compiler.
|
|
|
|
// Issue 2700, among other things.
|
|
|
|
// Does not compile.
|
|
|
|
|
2011-11-09 02:58:53 -07:00
|
|
|
package main
|
|
|
|
|
2012-01-24 05:53:00 -07:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
2011-11-09 02:58:53 -07:00
|
|
|
|
|
|
|
type I interface {
|
2012-01-24 05:53:00 -07:00
|
|
|
M()
|
2011-11-09 02:58:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func main(){
|
2012-01-24 05:53:00 -07:00
|
|
|
var x I
|
|
|
|
switch x.(type) {
|
|
|
|
case string: // ERROR "impossible"
|
|
|
|
println("FAIL")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Issue 2700: if the case type is an interface, nothing is impossible
|
|
|
|
|
|
|
|
var r io.Reader
|
|
|
|
|
|
|
|
_, _ = r.(io.Writer)
|
|
|
|
|
|
|
|
switch r.(type) {
|
|
|
|
case io.Writer:
|
|
|
|
}
|
2012-02-06 10:35:29 -07:00
|
|
|
|
|
|
|
// Issue 2827.
|
2012-09-28 09:30:30 -06:00
|
|
|
switch _ := r.(type) { // ERROR "invalid variable name _|no new variables"
|
2012-02-06 10:35:29 -07:00
|
|
|
}
|
2011-11-09 02:58:53 -07:00
|
|
|
}
|
2012-01-24 05:53:00 -07:00
|
|
|
|
|
|
|
|