Skip to content

Commit 5b634ac

Browse files
Fix ID collision between partial eval and AST pruner (#700)
1 parent 75ed853 commit 5b634ac

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

interpreter/prune.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,19 @@ type astPruner struct {
6868
// the overloads accordingly.
6969
func PruneAst(expr *exprpb.Expr, macroCalls map[int64]*exprpb.Expr, state EvalState) *exprpb.ParsedExpr {
7070
pruneState := NewEvalState()
71+
maxID := int64(1)
7172
for _, id := range state.IDs() {
7273
v, _ := state.Value(id)
7374
pruneState.SetValue(id, v)
75+
if id > maxID {
76+
maxID = id + 1
77+
}
7478
}
7579
pruner := &astPruner{
7680
expr: expr,
7781
macroCalls: macroCalls,
7882
state: pruneState,
79-
nextExprID: 1}
83+
nextExprID: maxID}
8084
newExpr, _ := pruner.maybePrune(expr)
8185
return &exprpb.ParsedExpr{
8286
Expr: newExpr,

interpreter/prune_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ var testCases = []testInfo{
152152
expr: `test in {'a': 1, 'field': [test, 3]}.field`,
153153
out: `test in {"a": 1, "field": [test, 3]}.field`,
154154
},
155+
{
156+
in: partialActivation(map[string]any{"foo": "bar"}, "r.attr"),
157+
expr: `foo == "bar" && r.attr.loc in ["GB", "US"]`,
158+
out: `r.attr.loc in ["GB", "US"]`,
159+
},
155160
// TODO: the output of an expression like this relies on either
156161
// a) doing replacements on the original macro call, or
157162
// b) mutating the macro call tracking data rather than the core

0 commit comments

Comments
 (0)