Source file
test/fixedbugs/issue23017.go
1
2
3
4
5
6
7
8
9
10 package main
11
12 import "fmt"
13
14 func main() {}
15
16 func init() {
17 var m = map[int]int{}
18 var p *int
19
20 defer func() {
21 recover()
22 check(1, len(m))
23 check(42, m[2])
24 }()
25 m[2], *p = 42, 2
26 }
27
28 func init() {
29 var m = map[int]int{}
30 p := []int{}
31
32 defer func() {
33 recover()
34 check(1, len(m))
35 check(2, m[2])
36 }()
37 m[2], p[1] = 2, 2
38 }
39
40 func init() {
41 type P struct{ i int }
42 var m = map[int]int{}
43 var p *P
44
45 defer func() {
46 recover()
47 check(1, len(m))
48 check(3, m[2])
49 }()
50 m[2], p.i = 3, 2
51 }
52
53 func init() {
54 type T struct{ i int }
55 var x T
56 p := &x
57 p, p.i = new(T), 4
58 check(4, x.i)
59 }
60
61 func init() {
62 var m map[int]int
63 var a int
64 var p = &a
65
66 defer func() {
67 recover()
68 check(5, *p)
69 }()
70 *p, m[2] = 5, 2
71 }
72
73 var g int
74
75 func init() {
76 var m map[int]int
77 defer func() {
78 recover()
79 check(0, g)
80 }()
81 m[0], g = 1, 2
82 }
83
84 func init() {
85 type T struct{ x struct{ y int } }
86 var x T
87 p := &x
88 p, p.x.y = new(T), 7
89 check(7, x.x.y)
90 check(0, p.x.y)
91 }
92
93 func init() {
94 type T *struct{ x struct{ y int } }
95 x := struct{ y int }{0}
96 var q T = &struct{ x struct{ y int } }{x}
97 p := q
98 p, p.x.y = nil, 7
99 check(7, q.x.y)
100 }
101
102 func init() {
103 x, y := 1, 2
104 x, y = y, x
105 check(2, x)
106 check(1, y)
107 }
108
109 func check(want, got int) {
110 if want != got {
111 panic(fmt.Sprintf("wanted %d, but got %d", want, got))
112 }
113 }
114
View as plain text