blob: 23577098e4953129f3a2f61ab8b38d310938bf77 [file] [log] [blame]
philhofer295307a2017-03-13 15:03:17 -07001// errorcheck -0 -d=ssa/opt/debug=3
2
3package main
4
5// Trivial interface call devirtualization test.
6
7type real struct {
8 value int
9}
10
11func (r *real) Value() int { return r.value }
12
13type Valuer interface {
14 Value() int
15}
16
17type indirectiface struct {
18 a, b, c int
19}
20
21func (i indirectiface) Value() int {
22 return i.a + i.b + i.c
23}
24
25func 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 // Can't do types that aren't "direct" interfaces (yet).
35 r = indirectiface{3, 4, 5}
36 if r.Value() != 12 {
37 panic("not 12")
38 }
39}