1
2
3
4
5 package issue38068
6
7
8
9 type A struct {
10 s string
11 next *A
12 prev *A
13 }
14
15
16 func (a A) double(x string, y int) string {
17 if y == 191 {
18 a.s = ""
19 }
20 q := a.s + "a"
21 r := a.s + "b"
22 return q + r
23 }
24
25
26 func (a A) triple(x string, y int) string {
27 q := a.s
28 if y == 998877 {
29 a.s = x
30 }
31 r := a.s + a.s
32 return q + r
33 }
34
35 type methods struct {
36 m1 func(a *A, x string, y int) string
37 m2 func(a *A, x string, y int) string
38 }
39
40
41
42 func P(a *A, ms *methods) {
43 if a != nil {
44 defer func() { println("done") }()
45 }
46 println(ms.m1(a, "a", 2))
47 println(ms.m2(a, "b", 3))
48 }
49
50 func G(x *A, n int) {
51 if n <= 0 {
52 println(n)
53 return
54 }
55
56
57 var a, b A
58 a.next = x
59 a.prev = &b
60 x = &a
61 G(x, n-2)
62 }
63
64 var M methods
65
66 func F() {
67 M.m1 = (*A).double
68 M.m2 = (*A).triple
69 G(nil, 100)
70 }
71
View as plain text