Source file
test/fixedbugs/issue16130.go
1
2
3
4
5
6
7
8
9
10
11 package main
12
13 import (
14 "fmt"
15 "runtime"
16 "strings"
17 )
18
19 type I interface {
20 Get() int
21 }
22
23 func main() {
24 defer func() {
25 r := recover()
26 if r == nil {
27 panic("expected panic")
28 }
29 re, ok := r.(runtime.Error)
30 if !ok {
31 panic(fmt.Sprintf("got %T, expected runtime.Error", r))
32 }
33 if !strings.Contains(re.Error(), "interface conversion") {
34 panic(fmt.Sprintf("got %q, expected interface conversion error", re.Error()))
35 }
36 }()
37 e := (interface{})(0)
38 if _, ok := e.(I); ok {
39 panic("unexpected interface conversion success")
40 }
41 fmt.Println(e.(I))
42 panic("unexpected interface conversion success")
43 }
44
View as plain text