SIGN IN SIGN UP

topdown: (shallow) partial eval of ref to empty collection

...when a `with` statement is in the collection's rules.

The presence of the `with` statement triggers a conditon in saveRequired
(len(node.With) > 0), and that in turn makes the shallow partial eval of
a virtual partial doc turn use its `partialEvalSupport` code path.

That path would fall back to its empty term when no rule body would be
defined: ast.NewSet() or ast.NewObject() accordingly. However, if the
call site referenced an element, or a key, instead of the collection
itself, then the result would be an unsafe partial support rule.

Now, we'll check if the reference was the collection, or any part of it;
if it's the latter, we'll stop evaluating: an empty set has no elements,
and empty object has no keys.

There's one oddity compared to non-shallow eval now: when shallow is off,
the results flip: in the tests, `set() = a` and `{} = a` become `a = set()`
and `a = {}` accordingly.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
S
Stephan Renatus committed
8746c723426324dd9a1a5a4cec2d229fa265eb01
Parent: 7f75625
Committed by Torin Sandall <torinsandall@gmail.com> on 6/10/2021, 3:32:07 PM