Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

topdown: Fix confusing error message for minus operator #4090

Merged
merged 1 commit into from Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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