From a1f2d3bf1dae85749847b367e6c6cbe36ea4554c Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 19 Dec 2019 18:32:04 +0100 Subject: [PATCH] fix: isNil was not forwarding result when used in a branch expression --- _test/nil1.go | 12 ++++++++++++ interp/run.go | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 _test/nil1.go diff --git a/_test/nil1.go b/_test/nil1.go new file mode 100644 index 000000000..040699bde --- /dev/null +++ b/_test/nil1.go @@ -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 diff --git a/interp/run.go b/interp/run.go index 48c4eb255..9582aefde 100644 --- a/interp/run.go +++ b/interp/run.go @@ -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 @@ -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