opa
opa copied to clipboard
"unexpected assign token" error is almost always wrong and masks real issues
This was reported as a side-effect in #6433 but this is actually the main issue, so I'll close that in favor if this one. We really ought to look into the parse error of "unexpected assign token" as it's:
- Very frequently reported
- Wrong
- Hides actual issues from users, thus making Rego development harder than it should be
This is especially problematic for users new to Rego, which makes this a high priority to fix.
Compare:
package play
s := "a
1 error occurred: policy.rego:3: rego_parse_error: unexpected assign token: expected rule value term (e.g., s := <VALUE> { ... })
s := "a
vs.
package play
s = "a
3 errors occurred:
policy.rego:3: rego_parse_error: non-terminated string
s = "a
^
policy.rego:3: rego_parse_error: illegal token
s = "a
^
policy.rego:3: rego_parse_error: illegal token
s = "a
^
But essentially any errors reported on the right hand side of the assignment operator (:=) will be reported the same way, while using = instead provides the user with the actual error.
Using := is recommended over = and has been for a long time, which explains why this is such a commonly reported error.