Source file
test/fixedbugs/issue49512.go
1
2
3
4
5
6
7 package main
8
9 type S struct{
10 m1Called, m2Called bool
11 }
12
13 func (s *S) M1(int) (int, int) {
14 s.m1Called = true
15 return 0, 0
16 }
17
18 func (s *S) M2(int) (int, int) {
19 s.m2Called = true
20 return 0, 0
21 }
22
23 type C struct {
24 calls []func(int) (int, int)
25 }
26
27 func makeC() Funcs {
28 return &C{}
29 }
30
31 func (c *C) Add(fn func(int) (int, int)) Funcs {
32 c.calls = append(c.calls, fn)
33 return c
34 }
35
36 func (c *C) Call() {
37 for _, fn := range c.calls {
38 fn(0)
39 }
40 }
41
42 type Funcs interface {
43 Add(func(int) (int, int)) Funcs
44 Call()
45 }
46
47 func main() {
48 s := &S{}
49 c := makeC().Add(s.M1).Add(s.M2)
50 c.Call()
51 if !s.m1Called || !s.m2Called {
52 panic("missed method call")
53 }
54 }
55
View as plain text