diff --git a/interpreter/prune.go b/interpreter/prune.go index 24c7e79d..85b3b065 100644 --- a/interpreter/prune.go +++ b/interpreter/prune.go @@ -68,15 +68,19 @@ type astPruner struct { // the overloads accordingly. func PruneAst(expr *exprpb.Expr, macroCalls map[int64]*exprpb.Expr, state EvalState) *exprpb.ParsedExpr { pruneState := NewEvalState() + maxID := int64(1) for _, id := range state.IDs() { v, _ := state.Value(id) pruneState.SetValue(id, v) + if id > maxID { + maxID = id + 1 + } } pruner := &astPruner{ expr: expr, macroCalls: macroCalls, state: pruneState, - nextExprID: 1} + nextExprID: maxID} newExpr, _ := pruner.maybePrune(expr) return &exprpb.ParsedExpr{ Expr: newExpr, diff --git a/interpreter/prune_test.go b/interpreter/prune_test.go index dd257490..fb7855d5 100644 --- a/interpreter/prune_test.go +++ b/interpreter/prune_test.go @@ -152,6 +152,11 @@ var testCases = []testInfo{ expr: `test in {'a': 1, 'field': [test, 3]}.field`, out: `test in {"a": 1, "field": [test, 3]}.field`, }, + { + in: partialActivation(map[string]any{"foo": "bar"}, "r.attr"), + expr: `foo == "bar" && r.attr.loc in ["GB", "US"]`, + out: `r.attr.loc in ["GB", "US"]`, + }, // TODO: the output of an expression like this relies on either // a) doing replacements on the original macro call, or // b) mutating the macro call tracking data rather than the core