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 7// Test that interface conversion fails when method is missing. 8 9package main 10 11type I interface { 12 Foo() 13} 14 15func main() { 16 shouldPanic(p1) 17} 18 19func p1() { 20 var s *S 21 var i I 22 var e interface{} 23 e = s 24 i = e.(I) 25 _ = i 26} 27 28type S struct{} 29 30func (s *S) _() {} 31 32func shouldPanic(f func()) { 33 defer func() { 34 if recover() == nil { 35 panic("function should panic") 36 } 37 }() 38 f() 39} 40