Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix panic caused by assignment rewriting
During the assignment rewriting stages, variables that have been assigned locally are rewritten, e.g., k := "foo"; {k: 1} becomes __local0__ = "foo"; {__local0__: 1}. Previously, the rewriting would simply mutate all of the term values without considering where the term was defined. The problem with this was that it would corrupt the object's hashtable if the rewritten term was an object key. This commit resolves the issue by making a copy of the object key before mutating the term value. This approach requires the compiler to copy the object as well. If this proves to be a performance bottleneck, we can do something more clever. Note, it's arguable that the Object struct should not allow keys to be mutated at all. This would be tricky given the current Object interface. Perhaps we can improve this in the future to avoid similar issues. These changes also resolve an issue with the rewritten var set returned by the query compiler. Previously, all seen vars were returned in the set (as opposed to only those that had been redeclared.) When the query compiler inverts the map before returning it could accidentally elide vars, e.g., given {a: b, b: b} if it inverted this to {b: a} then the output would be correct but if it inverted this to {b: b} (which it could depending on the iteration order) the output would be incorrect. Fixes open-policy-agent#1125 Signed-off-by: Torin Sandall <[email protected]>
- Loading branch information