Source file
test/interface/assertinline.go
1
2
3
4
5
6
7 package p
8
9 func assertptr(x interface{}) *int {
10 return x.(*int)
11 }
12
13 func assertptr2(x interface{}) (*int, bool) {
14 z, ok := x.(*int)
15 return z, ok
16 }
17
18 func assertfunc(x interface{}) func() {
19 return x.(func())
20 }
21
22 func assertfunc2(x interface{}) (func(), bool) {
23 z, ok := x.(func())
24 return z, ok
25 }
26
27 func assertstruct(x interface{}) struct{ *int } {
28 return x.(struct{ *int })
29 }
30
31 func assertstruct2(x interface{}) (struct{ *int }, bool) {
32 z, ok := x.(struct{ *int })
33 return z, ok
34 }
35
36 func assertbig(x interface{}) complex128 {
37 return x.(complex128)
38 }
39
40 func assertbig2(x interface{}) (complex128, bool) {
41 z, ok := x.(complex128)
42 return z, ok
43 }
44
45 func assertbig2ok(x interface{}) (complex128, bool) {
46 _, ok := x.(complex128)
47 return 0, ok
48 }
49
50 func assertslice(x interface{}) []int {
51 return x.([]int)
52 }
53
54 func assertslice2(x interface{}) ([]int, bool) {
55 z, ok := x.([]int)
56 return z, ok
57 }
58
59 func assertslice2ok(x interface{}) ([]int, bool) {
60 _, ok := x.([]int)
61 return nil, ok
62 }
63
64 type I interface {
65 foo()
66 }
67
68 func assertInter(x interface{}) I {
69 return x.(I)
70 }
71 func assertInter2(x interface{}) (I, bool) {
72 z, ok := x.(I)
73 return z, ok
74 }
75
View as plain text