1// run 2 3// Copyright 2009 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 7package main 8 9type T struct {a, b int}; 10 11func println(x, y int) { } 12 13func f(x interface{}) interface{} { 14 type T struct {a, b int}; 15 16 if x == nil { 17 return T{2, 3}; 18 } 19 20 t := x.(T); 21 println(t.a, t.b); 22 return x; 23} 24 25func main() { 26 inner_T := f(nil); 27 f(inner_T); 28 29 shouldPanic(p1) 30} 31 32func p1() { 33 outer_T := T{5, 7}; 34 f(outer_T); 35} 36 37func shouldPanic(f func()) { 38 defer func() { 39 if recover() == nil { 40 panic("function should panic") 41 } 42 }() 43 f() 44} 45 46/* 47This prints: 48 492 3 505 7 51 52but it should crash: The type assertion on line 18 should fail 53for the 2nd call to f with outer_T. 54*/ 55