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