Source
Follow-up from ako's review on PR #337 (merged as part of open PR).
Problem
Several microflow builder passes open-code the same recursive AST walk over MicroflowStatement bodies, each with a nearly identical switch on statement types. Concrete examples:
- `planMicroflowCallOutputDeclarations` (inner `walk`) in `cmd_microflows_builder.go`
- `countMicroflowCallOutputs` in the same file
- `collectListInputVariables` / `collectObjectInputVariables` in `cmd_microflows_builder_graph.go`
- `statementVarRefs` / `statementsVarRefs` in `cmd_microflows_builder_varutil.go`
- `bodyReturns` in `validate_microflow.go`
Each copy is ~40 lines of switch boilerplate with an `ErrorHandling` recurse arm. When a new statement type gains an `ErrorHandling` field or nested body, it must be added in every place — this is how the bugs in PR #337 (issue #405) and PR #362 surfaced.
Expected behavior
A single shared helper:
```go
func walkStatements(body []ast.MicroflowStatement, fn func(ast.MicroflowStatement))
```
does the recursion (including `IfStmt`/`LoopStmt`/`WhileStmt` bodies and every `ErrorHandling.Body`). Each caller supplies the per-node callback only. Adding a new statement type with its own body requires exactly one edit in one place.
Proposed fix
- Introduce `walkStatements(body, fn)` in `cmd_microflows_builder_varutil.go` (or a new `cmd_microflows_builder_walk.go`).
- Rewrite the existing walkers to call it with their per-node logic.
- Keep `statementVarRefs` as is — that's the per-node logic, not the walker.
Related
Source
Follow-up from ako's review on PR #337 (merged as part of open PR).
Problem
Several microflow builder passes open-code the same recursive AST walk over MicroflowStatement bodies, each with a nearly identical switch on statement types. Concrete examples:
Each copy is ~40 lines of switch boilerplate with an `ErrorHandling` recurse arm. When a new statement type gains an `ErrorHandling` field or nested body, it must be added in every place — this is how the bugs in PR #337 (issue #405) and PR #362 surfaced.
Expected behavior
A single shared helper:
```go
func walkStatements(body []ast.MicroflowStatement, fn func(ast.MicroflowStatement))
```
does the recursion (including `IfStmt`/`LoopStmt`/`WhileStmt` bodies and every `ErrorHandling.Body`). Each caller supplies the per-node callback only. Adding a new statement type with its own body requires exactly one edit in one place.
Proposed fix
Related