opa
opa copied to clipboard
Type match error in object literal with set keys
The following policy is rejected by the type checker:
package bin
a := {1, 2, 3, 4}
b := {3, 4, 5}
c := {4, 5, 6}
d := {
a: b,
[1, 2]: c,
}
# this results in a compile error due to type mismatch
output {
d == {
[1, 2]: {4, 5, 6},
{1, 2, 3, 4}: {3, 4, 5}
}
}
The error:
1 error occurred: policy.rego:16: rego_type_error: match error
left : object<[1 2]: set[number]>[set[number]: set[number]]
right : object<[1 2]: set[number], [1 2 3 4]: set[number]>
It looks like the type checker is rejecting the equals expression because the static property on the RHS does not unify with the dynamic property on the LHS.
Changing a
to define an array a := [1, 2, 3, 4]
makes the type-checker happy. Naturally, this will however make the equality in output
fail (set != array, even though their members are the same).
The key of a static object property is a JSON value; could this be the culprit? Static properties with a set key will be turned into an array key, which then fails the comparison to the corresponding dynamic set-key property.
This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.