feat: allow expressions in add-to-list statements#362
feat: allow expressions in add-to-list statements#362hjotha wants to merge 2 commits intomendixlabs:mainfrom
Conversation
584c166 to
c5f2437
Compare
ako
left a comment
There was a problem hiding this comment.
Review — feat: allow expressions in add-to-list statements
Overview
Clean feature extension — grammar change is minimal (ADD expression TO VARIABLE), the visitor dual-sets Item and Value for backward compat, and the builder fallback chain is correct. The proposal and skill docs are good.
Moderate: validate_microflow.go and builder_graph.go only track s.Item, not s.Value
Two places consume AddToListStmt and look only at s.Item:
validate_microflow.go:425:
case *ast.AddToListStmt:
refs = append(refs, s.Item, s.List)cmd_microflows_builder_graph.go:312:
case *ast.AddToListStmt:
if s.Item != "" {
inputs[s.Item] = true
}For add head($SourceItems) to $Items, s.Item = "" and s.Value = CallExpr{...}. Neither place sees $SourceItems as a referenced variable — the validator will silently skip it (missing "variable not declared" check) and the flow graph won't include it in the activity's input set (affecting layout/ordering analysis).
Fix: walk the expression when s.Value != nil:
case *ast.AddToListStmt:
if s.Value != nil {
refs = append(refs, exprVarRefs(s.Value)...)
} else {
refs = append(refs, s.Item)
}
refs = append(refs, s.List)Same pattern in builder_graph.go:
case *ast.AddToListStmt:
if s.Value != nil {
walkExpr(s.Value)
} else if s.Item != "" {
inputs[s.Item] = true
}Moderate: .test.mdl suffix — CI won't run the doctype example
mdl-examples/doctype-tests/add_expression_to_list.test.mdl is skipped by TestMxCheck_DoctypeScripts (same issue flagged in PRs #334 and #336). This is now the third PR in this batch with this suffix. Rename to .mdl.
Minor: Item field leaves a maintenance trap in the AST
AddToListStmt.Item is now a derived shadow of Value — set only when Value is a VariableExpr, used only as a fallback when Value is nil. Any code path that constructs AddToListStmt manually with only Item set (e.g., tests, codegen) will silently get the old behavior without setting Value, making the dual-state confusing. The AST comment says "kept for simple $Var compatibility" — consider whether the field is still needed at all, or whether the builder fallback "$" + s.Item can be dropped in favour of always requiring Value.
Minor: TestAddToListKeepsSimpleVariableCompatibility doesn't assert Value
The test checks addStmt.Item == "Order" but not that addStmt.Value is a *ast.VariableExpr{Name: "Order"}. The dual-state behaviour of the visitor is only half-tested.
Positive
- Grammar change is backward-compatible: bare
$Itemis still a validexpression, so existing scripts parse unchanged. - Builder fallback chain (
exprToString(Value)→"$" + Item) is safe and correctly prioritises the expression. - Visitor correctly identifies
VariableExprto populateItemfor the legacy path.
AI Code ReviewLet me review this pull request step by step against the checklist. Summary of ChangesThis PR adds support for expression-valued add-to-list statements in MDL (Mendix Definition Language), allowing syntax like The changes include:
Review Against ChecklistOverlap & duplication
Looking at the proposals list, I see this PR implements the feature described in the new proposal The doctype test files listed don't show any existing test for this specific feature, so the new test file This doesn't appear to be re-documenting already-shipped features as new. MDL syntax design (for new or modified MDL syntax)
The PR modifies the Let's check against the guidelines:
The syntax design skill consulted check: The PR body doesn't explicitly mention consulting Full-stack consistency (for MDL features)New MDL commands or language features must be wired through the full pipeline. If the diff adds any MDL feature, check:
Checking the changes:
Wait, let me double-check the visitor. The PR description says: "Stores the parsed expression on AddToListStmt while preserving the legacy simple-variable Item field." Looking at the changes:
This suggests the visitor is correctly setting the Value field, but I don't see explicit visitor changes in the diff. Since ANTLR-generated visitors might not need manual changes if the grammar change is compatible, this might be OK. Let me check if there are any visitor changes I missed... Scanning the diff again, I don't see explicit changes to Actually, looking more carefully at the grammar change: This is a significant change - it's replacing a specific token (VARIABLE) with a general rule (expression). This would definitely require visitor changes to handle the new structure. Let me look for visitor changes again... I don't see any in the diff. This is likely an issue. Test coverage
The PR includes:
Security & robustness
I don't see obvious security issues in the changes. The expression handling goes through existing expression validation pathways. Scope & atomicity
This PR is scoped to a single feature: allowing expressions in add-to-list statements. All changes relate to this feature. Code quality
The changes look consistent. The legacy Bugs & correctness
I don't see obvious logic errors. The fallback logic in the executor looks correct: value := fb.exprToString(s.Value)
if value == "" && s.Item != "" {
value = "$" + s.Item
}Critical Issues Found
Moderate Issues Found
Minor Issues FoundNone specifically called out. What Looks Good
RecommendationI would request changes due to the critical issue of missing visitor updates. The grammar change requires corresponding changes in the visitor to properly parse expressions and populate the AST. Before approval, I need to see:
Once visitor changes are added, this PR looks strong and ready to merge. Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
AI Code ReviewWhat Looks GoodThe PR comprehensively implements the requested feature to allow expressions in add-to-list statements while maintaining backward compatibility. All necessary pipeline components are updated:
RecommendationApprove the PR. The implementation is complete, well-tested, and properly documented. No LSP updates are needed as this extends an existing statement rather than adding new language capabilities requiring LSP changes. The feature maintains backward compatibility and follows the project's architectural principles. Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
|
Review follow-up status: The current branch already includes the requested
I revalidated the focused executor coverage: go test ./mdl/executor -run 'AddToList|ExpressionToList|StatementVarRefs' -count=1 |
Studio Pro stores list-add values as expression strings, but MDL only accepted `add $Item to $List` and the AST kept only a bare item variable. Round-tripping a list-add action whose value is an attribute path or function call could therefore lose the original expression shape. The grammar now accepts `add expression to $List`, the visitor stores the parsed expression while keeping the simple-variable compatibility field, and the builder writes the expression value back to the `ChangeListAction`. The existing variable-only form remains supported. Tests cover parser and builder behavior for expression and simple-variable forms. The branch also adds a draft proposal, doctype fixture, quick-reference entry, and skill guidance; `mxcli check` on the fixture plus make build, make lint-go, and make test pass locally.
Symptom: expression-valued add-to-list statements were parsed and written correctly, but validator and builder graph walkers only inspected the legacy Item field. Root cause: the new Value expression path was not wired into referenced-variable and object-input collection, so variables used only inside add expressions could be missed. Fix: walk AddToListStmt.Value when present, keep the legacy Item fallback for synthetic callers, and rename the doctype example to .mdl so CI executes it. Tests: added builder, validator, and visitor assertions; ran mxcli check for the doctype fixture plus make build and make test.
57f7487 to
7e0bf0e
Compare
AI Code ReviewReview SummaryThis PR implements support for expressions in add-to-list statements (e.g., Critical IssuesNone found. Moderate IssuesNone found. Minor Issues
What Looks Good
RecommendationApprove the PR. The implementation is complete, well-tested, and adheres to all architectural and design guidelines. The feature satisfies the requirement to preserve Studio Pro's expression-valued list actions while maintaining full backward compatibility. No blocking issues were identified. Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
Summary
Allows microflow add-to-list statements to preserve expression-valued add items.
Changes
add $Item to $Listtoadd expression to $List.AddToListStmtwhile preserving the legacy simple-variableItemfield.ChangeListAction.Valueduring rebuild.Validation
go test ./mdl/visitor -run TestAddToListgo test ./mdl/executor -run TestAddToListBuilder./bin/mxcli check mdl-examples/doctype-tests/add_expression_to_list.test.mdlmake buildmake lint-gomake testCloses #361
Part of #352
Part of #332