Skip to content

some x in xs: semantics with shadowing, error unclear #4202

Open
@srenatus

Description

$ opa run
OPA 0.36.0-dev (commit b20b7e6e5-dirty, built at 2022-01-04T11:30:15Z)

Run 'help' to see a list of commands and check for updates.

> import future.keywords
> y := "a"
Rule 'y' defined in package repl. Type 'show' to see rules.
> some [a, 10] in [[y, 10]]
+-----+
|  a  |
+-----+
| "a" |
+-----+

That much is clear: a is a declared variable, and it is bound to whatever [[y, 10]] resolved to ([["a", 10]]).

However, shadowing y yields:

> some [y, 10] in [[y, 10]]
1 error occurred: 1:1: rego_unsafe_var_error: var y is unsafe

The problem is not that y shadows the declared (top-level) var y, at least not alone:

> x := "?"
Rule 'x' defined in package repl. Type 'show' to see rules.
> some [x, 10] in [[y, 10]]
+-----+
|  x  |
+-----+
| "a" |
+-----+
>

x shadows in the same way, but it does yield a result.

Metadata

Assignees

Labels

Type

No type

Projects

  • Status

    Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions