wasm: Fix planner to check call expression for false return value

The planner was not checking call expression results for false return
values that ought to cause evaluation to fail. This meant that
evaluation would continue to the next expression.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit is contained in:
Torin Sandall
2019-11-08 15:41:44 -05:00
parent 0ed978c688
commit e60fc2fdfa
2 changed files with 31 additions and 2 deletions
+14 -1
View File
@@ -678,7 +678,7 @@ func (p *Planner) planExprCall(e *ast.Expr, iter planiter) error {
if len(operands) == arity {
// rule: f(x) = x { ... }
// call: f(x) == 1 or f(x) # result not captured
// call: f(x) # result not captured
return p.planCallArgs(operands, 0, args, func(args []ir.Local) error {
p.ltarget = p.newLocal()
p.appendStmt(&ir.CallStmt{
@@ -686,6 +686,19 @@ func (p *Planner) planExprCall(e *ast.Expr, iter planiter) error {
Args: args,
Result: p.ltarget,
})
falsy := p.newLocal()
p.appendStmt(&ir.MakeBooleanStmt{
Value: false,
Target: falsy,
})
p.appendStmt(&ir.NotEqualStmt{
A: p.ltarget,
B: falsy,
})
return iter()
})
} else if len(operands) == arity+1 {
+17 -1
View File
@@ -103,4 +103,20 @@ cases:
package x
f(x) = 1
f(x) = 2
want_error: var assignment conflict
want_error: var assignment conflict
- note: 'false result'
query: data.test.p = x
modules:
- |
package test
f(x) = false
p = true { f(1) }
want_defined: false
- note: 'negated false result'
query: data.test.p = x
modules:
- |
package test
f(x) = false
p = true { not f(1) }
want_defined: true