Source file
test/fixedbugs/issue82930.go
1
2
3
4
5
6
7 package main
8
9 import "runtime"
10
11
12
13
14 func growStack(n int) {
15 var buf [1024]byte
16 if n > 0 {
17 growStack(n - 1)
18 }
19 runtime.KeepAlive(&buf)
20 }
21
22
23
24
25
26
27
28 func growSeq() func(func(int) bool) {
29 return func(yield func(int) bool) {
30 growStack(256)
31 yield(0)
32 }
33 }
34
35
36
37
38
39 func shrinkSeq() func(func(int) bool) {
40 return func(yield func(int) bool) {
41 runtime.GC()
42 yield(0)
43 }
44 }
45
46 func f(seq func() func(func(int) bool)) (r any) {
47 defer func() {
48 if recover() != nil {
49 r = nil
50 }
51 }()
52 func() {
53 defer func() {
54 for range seq() {
55 r = recover()
56 }
57 }()
58 panic("boom")
59 }()
60 return r
61 }
62
63 func main() {
64
65
66 ch := make(chan any)
67 go func() { ch <- f(growSeq) }()
68 if r := <-ch; r != "boom" {
69 panic("grow: recover in the loop body did not recover the panic")
70 }
71
72
73
74 go func() {
75 growStack(256)
76 ch <- f(shrinkSeq)
77 }()
78 if r := <-ch; r != "boom" {
79 panic("shrink: recover in the loop body did not recover the panic")
80 }
81 }
82
View as plain text