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 9package main 10 11func main() { 12 n := foo() 13 if n != 2 { 14 println(n) 15 panic("wrong return value") 16 } 17} 18 19type terr struct{} 20 21func 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 35func foo1() { 36 panic(terr{}) 37} 38