Source file
test/fixedbugs/issue46725.go
1
2
3
4
5
6
7 package main
8
9 import "runtime"
10
11 type T [4]int
12
13
14 func g(x []*T) ([]*T, []*T) { return x, x }
15
16 func main() {
17 const Jenny = 8675309
18 s := [10]*T{{Jenny}}
19
20 done := make(chan struct{})
21 runtime.SetFinalizer(s[0], func(p *T) { close(done) })
22
23 var h, _ interface{} = g(s[:])
24
25 if wait(done) {
26 panic("GC'd early")
27 }
28
29 if h.([]*T)[0][0] != Jenny {
30 panic("lost Jenny's number")
31 }
32
33 if !wait(done) {
34 panic("never GC'd")
35 }
36 }
37
38 func wait(done <-chan struct{}) bool {
39 for i := 0; i < 10; i++ {
40 runtime.GC()
41 select {
42 case <-done:
43 return true
44 default:
45 }
46 }
47 return false
48 }
49
View as plain text