Skip to content

Commit fa1c909

Browse files
hjothamendixclaude
andcommitted
fix: track add-to-list expression vars in error-handler statement refs
errorHandlerStatementVarRefs in cmd_microflows_builder_flows.go was still mirroring the old (s.Item, s.List) pattern. For `add head($SourceItems) to $Items` the expression-valued case, s.Item is empty and s.Value carries the expression — so $SourceItems was silently dropped from the reference set used by error-handler flow analysis (same class of bug ako flagged in validate_microflow.go and builder_graph.go, which were already fixed). Walk s.Value when present; fall back to s.Item for the simple-variable legacy path. New regression test TestErrorHandlerStatementVarRefsSeesAddExpressionValue guards both the expression ref and the list ref. Addresses review feedback on #362. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a0c3ef4 commit fa1c909

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

mdl/executor/cmd_microflows_builder_add_to_list_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ func TestCollectObjectInputVariablesSeesAddExpressionValue(t *testing.T) {
5858
}
5959
}
6060

61+
func TestErrorHandlerStatementVarRefsSeesAddExpressionValue(t *testing.T) {
62+
stmt := &ast.AddToListStmt{
63+
Value: &ast.FunctionCallExpr{
64+
Name: "head",
65+
Arguments: []ast.Expression{
66+
&ast.VariableExpr{Name: "SourceItems"},
67+
},
68+
},
69+
List: "Items",
70+
}
71+
72+
refs := errorHandlerStatementVarRefs(stmt)
73+
74+
seenSource := false
75+
seenList := false
76+
for _, r := range refs {
77+
if r == "SourceItems" {
78+
seenSource = true
79+
}
80+
if r == "Items" {
81+
seenList = true
82+
}
83+
}
84+
if !seenSource {
85+
t.Errorf("expected $SourceItems to be tracked from add expression: %v", refs)
86+
}
87+
if !seenList {
88+
t.Errorf("expected $Items (list) to be tracked: %v", refs)
89+
}
90+
}
91+
6192
func lastChangeListAction(t *testing.T, fb *flowBuilder) *microflows.ChangeListAction {
6293
t.Helper()
6394

mdl/executor/cmd_microflows_builder_flows.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,12 @@ func errorHandlerStatementVarRefs(stmt ast.MicroflowStatement) []string {
505505
refs = append(refs, exprVarRefs(arg)...)
506506
}
507507
case *ast.AddToListStmt:
508-
refs = append(refs, s.Item, s.List)
508+
if s.Value != nil {
509+
refs = append(refs, exprVarRefs(s.Value)...)
510+
} else if s.Item != "" {
511+
refs = append(refs, s.Item)
512+
}
513+
refs = append(refs, s.List)
509514
case *ast.RemoveFromListStmt:
510515
refs = append(refs, s.Item, s.List)
511516
}

0 commit comments

Comments
 (0)