github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/test/typeswitch3.go (about) 1 // errorcheck 2 3 // Copyright 2011 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // Verify that erroneous type switches are caught be the compiler. 8 // Issue 2700, among other things. 9 // Does not compile. 10 11 package main 12 13 import ( 14 "io" 15 ) 16 17 type I interface { 18 M() 19 } 20 21 func main(){ 22 var x I 23 switch x.(type) { 24 case string: // ERROR "impossible" 25 println("FAIL") 26 } 27 28 // Issue 2700: if the case type is an interface, nothing is impossible 29 30 var r io.Reader 31 32 _, _ = r.(io.Writer) 33 34 switch r.(type) { 35 case io.Writer: 36 } 37 38 // Issue 2827. 39 switch _ := r.(type) { // ERROR "invalid variable name _|no new variables" 40 } 41 } 42 43