Debian Codegraph @

test/fixedbugs/issue4066.go

raw
1 // run
2
3 // Copyright 2012 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 // issue 4066: return values not being spilled eagerly enough
8
9 package main
10
11 func main() {
12 n := foo()
13 if n != 2 {
14 println(n)
15 panic("wrong return value")
16 }
17 }
18
19 type terr struct{}
20
21 func foo() (val int) {
22 val = 0
23 defer func() {
24 if x := recover(); x != nil {
25 _ = x.(terr)
26 }
27 }()
28 for {
29 val = 2
30 foo1()
31 }
32 panic("unreachable")
33 }
34
35 func foo1() {
36 panic(terr{})
37 }