Skip to content

Commit

Permalink
fix: isNil was not forwarding result when used in a branch expression
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Dec 19, 2019
1 parent 3cd3764 commit a1f2d3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions _test/nil1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

func main() {
var a error = nil

if a == nil || a.Error() == "nil" {
println("a is nil")
}
}

// Output:
// a is nil
8 changes: 6 additions & 2 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2420,17 +2420,19 @@ func isNil(n *node) {
value = genValue(n.child[0])
}
tnext := getExec(n.tnext)
i := n.findex

if n.fnext != nil {
fnext := getExec(n.fnext)
n.exec = func(f *frame) bltn {
if value(f).IsNil() {
f.data[i].SetBool(true)
return tnext
}
f.data[i].SetBool(false)
return fnext
}
} else {
i := n.findex
n.exec = func(f *frame) bltn {
f.data[i].SetBool(value(f).IsNil())
return tnext
Expand All @@ -2446,17 +2448,19 @@ func isNotNil(n *node) {
value = genValue(n.child[0])
}
tnext := getExec(n.tnext)
i := n.findex

if n.fnext != nil {
fnext := getExec(n.fnext)
n.exec = func(f *frame) bltn {
if value(f).IsNil() {
f.data[i].SetBool(false)
return fnext
}
f.data[i].SetBool(true)
return tnext
}
} else {
i := n.findex
n.exec = func(f *frame) bltn {
f.data[i].SetBool(!value(f).IsNil())
return tnext
Expand Down

0 comments on commit a1f2d3b

Please sign in to comment.