Skip to content

Commit

Permalink
topdown: Fix confusing error message for minus operator (#4090)
Browse files Browse the repository at this point in the history
Fixes #1643

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
  • Loading branch information
tsandall committed Dec 3, 2021
1 parent b5212fc commit af4ad84
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
@@ -0,0 +1,27 @@
cases:
- data:
modules:
- |
package test
p {
{1} - 1
}
note: arithmetic/minus/type error
query: data.test.p = x
want_error: operand 2 must be set but got number
want_error_code: eval_type_error
strict_error: true
- data:
modules:
- |
package test
p {
1 - {1}
}
note: arithmetic/minus/type error
query: data.test.p = x
want_error: operand 2 must be number but got set
want_error_code: eval_type_error
strict_error: true
6 changes: 5 additions & 1 deletion topdown/arithmetic.go
Expand Up @@ -137,7 +137,11 @@ func builtinMinus(a, b ast.Value) (ast.Value, error) {
return nil, builtins.NewOperandTypeErr(1, a, "number", "set")
}

return nil, builtins.NewOperandTypeErr(2, b, "number", "set")
if ok2 {
return nil, builtins.NewOperandTypeErr(2, b, "set")
}

return nil, builtins.NewOperandTypeErr(2, b, "number")
}

func builtinRem(a, b ast.Value) (ast.Value, error) {
Expand Down

0 comments on commit af4ad84

Please sign in to comment.