]> Cypherpunks.ru repositories - gostls13.git/blobdiff - test/recover.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / test / recover.go
index 6287d65076d333eb7157d5c148040986e75a38f4..e4187c018f68a7e0d6b4bc7feb17af21e2ae4c4a 100644 (file)
@@ -1,6 +1,6 @@
 // run
 
-// Copyright 2010 The Go Authors.  All rights reserved.
+// Copyright 2010 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
@@ -63,6 +63,7 @@ func main() {
                test14reflect1()
                test14reflect2()
                test15()
+               test16()
        }
 }
 
@@ -114,10 +115,23 @@ func withoutRecover() {
        mustNotRecover() // because it's a sub-call
 }
 
+func withoutRecoverRecursive(n int) {
+       if n == 0 {
+               withoutRecoverRecursive(1)
+       } else {
+               v := recover()
+               if v != nil {
+                       println("spurious recover (recursive)", v)
+                       die()
+               }
+       }
+}
+
 func test1() {
-       defer mustNotRecover() // because mustRecover will squelch it
-       defer mustRecover(1)   // because of panic below
-       defer withoutRecover() // should be no-op, leaving for mustRecover to find
+       defer mustNotRecover()           // because mustRecover will squelch it
+       defer mustRecover(1)             // because of panic below
+       defer withoutRecover()           // should be no-op, leaving for mustRecover to find
+       defer withoutRecoverRecursive(0) // ditto
        panic(1)
 }
 
@@ -547,3 +561,27 @@ func test15() {
        defer f()
        panic(15)
 }
+
+func reflectFunc2(args []reflect.Value) (results []reflect.Value) {
+       // This will call reflectFunc3
+       args[0].Interface().(func())()
+       return nil
+}
+
+func reflectFunc3(args []reflect.Value) (results []reflect.Value) {
+       if v := recover(); v != nil {
+               println("spurious recover", v)
+               die()
+       }
+       return nil
+}
+
+func test16() {
+       defer mustRecover(16)
+
+       f2 := reflect.MakeFunc(reflect.TypeOf((func(func()))(nil)), reflectFunc2).Interface().(func(func()))
+       f3 := reflect.MakeFunc(reflect.TypeOf((func())(nil)), reflectFunc3).Interface().(func())
+       defer f2(f3)
+
+       panic(16)
+}