fix: nil recover case

This commit is contained in:
Nicholas Wiersma
2020-05-29 13:28:03 +02:00
committed by GitHub
parent 5d78c8ae27
commit 56d88ef89d
2 changed files with 16 additions and 5 deletions

15
_test/recover2.go Normal file
View File

@@ -0,0 +1,15 @@
package main
func main() {
println("hello")
var r interface{} = 1
r = recover()
if r == nil {
println("world")
}
}
// Output:
// hello
// world

View File

@@ -459,13 +459,9 @@ func _println(n *node) {
func _recover(n *node) {
tnext := getExec(n.tnext)
dest := genValue(n)
var err error
nilErr := reflect.ValueOf(valueInterface{n, reflect.ValueOf(&err).Elem()})
n.exec = func(f *frame) bltn {
if f.anc.recovered == nil {
dest(f).Set(nilErr)
} else {
if f.anc.recovered != nil {
dest(f).Set(reflect.ValueOf(valueInterface{n, reflect.ValueOf(f.anc.recovered)}))
f.anc.recovered = nil
}