Debian Codegraph @

test/devirt.go

raw
1 // errorcheck -0 -d=ssa/opt/debug=1
2
3 package main
4
5 // Trivial interface call devirtualization test.
6
7 type real struct {
8 value int
9 }
10
11 func (r *real) Value() int { return r.value }
12
13 type Valuer interface {
14 Value() int
15 }
16
17 type indirectiface struct {
18 a, b, c int
19 }
20
21 func (i indirectiface) Value() int {
22 return i.a + i.b + i.c
23 }
24
25 func main() {
26 var r Valuer
27 rptr := &real{value: 3}
28 r = rptr
29
30 if r.Value() != 3 { // ERROR "de-virtualizing call$"
31 panic("not 3")
32 }
33
34 r = indirectiface{3, 4, 5}
35 if r.Value() != 12 { // ERROR "de-virtualizing call$"
36 panic("not 12")
37 }
38 }