diff --git a/_test/or0.go b/_test/or0.go new file mode 100644 index 000000000..765ebeec5 --- /dev/null +++ b/_test/or0.go @@ -0,0 +1,9 @@ +package main + +func main() { + c := false + println(c || !c) +} + +// Output: +// true diff --git a/_test/or1.go b/_test/or1.go new file mode 100644 index 000000000..0dd73f8c3 --- /dev/null +++ b/_test/or1.go @@ -0,0 +1,9 @@ +package main + +func main() { + c := false + println(!c || c) +} + +// Output: +// true diff --git a/interp/cfg.go b/interp/cfg.go index 73a289de2..6d3652c49 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -1023,6 +1023,9 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) { n.child[1].tnext = n n.typ = n.child[0].typ n.findex = sc.add(n.typ) + if n.start.action == aNop { + n.start.gen = branch + } case lorExpr: n.start = n.child[0].start @@ -1031,6 +1034,9 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) { n.child[1].tnext = n n.typ = n.child[0].typ n.findex = sc.add(n.typ) + if n.start.action == aNop { + n.start.gen = branch + } case parenExpr: wireChild(n) diff --git a/interp/dot.go b/interp/dot.go index 8696a7711..8441128ff 100644 --- a/interp/dot.go +++ b/interp/dot.go @@ -38,7 +38,7 @@ func (n *node) astDot(out io.Writer, name string) { func (n *node) cfgDot(out io.Writer) { fmt.Fprintf(out, "digraph cfg {\n") n.Walk(nil, func(n *node) { - if n.kind == basicLit || n.kind == identExpr || n.tnext == nil { + if n.kind == basicLit || n.tnext == nil { return } var label string diff --git a/interp/run.go b/interp/run.go index 4ee7e1e93..d8b10b9f8 100644 --- a/interp/run.go +++ b/interp/run.go @@ -345,13 +345,16 @@ func not(n *node) { dest := genValue(n) 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).Bool() { + f.data[i].SetBool(true) return tnext } + f.data[i].SetBool(false) return fnext } } else {