feat: allow expressions in add-to-list statements#362
feat: allow expressions in add-to-list statements#362hjotha wants to merge 7 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 |
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 |
Symptom: all open PRs against main failed the shared build-and-test job in make test-integration, even when their local build/test/lint validation passed. The failures reproduced on origin/main, so they were baseline CI instability rather than PR-specific regressions. Root cause: TestWatcherDebounce could allow stale timer callbacks to send an extra message under slow scheduling, nanoflow integration fixtures used MDL syntax that no longer matched the grammar, and the doctype mx-check harness did not classify known page/nanoflow showcase consistency errors as expected limitations. Fix: guard watcher debounce callbacks with a generation counter, tighten the watcher burst test, update nanoflow fixtures to current MDL syntax, and extend the known consistency-error allowlist for showcase-only limitations. Tests: make build Tests: go test ./cmd/mxcli/tui -run TestWatcherDebounce -count=20 -v Tests: ./bin/mxcli check mdl-examples/doctype-tests/02b-nanoflow-examples.mdl Tests: go test -tags integration -count=1 -timeout 30m ./mdl/executor -run 'TestRoundtripNanoflow_(Loop|EnumParameter|Annotations)|TestMxCheck_DoctypeScripts/02b-nanoflow-examples.mdl|TestMxCheck_DoctypeScripts/03-page-examples.mdl' -v Tests: make test Tests: make lint-go Tests: make test-integration
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.
7e0bf0e to
3df26fe
Compare
AI Code ReviewReview SummaryCritical Issues
Moderate Issues
Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
|
CI stabilization note: merged #412 into this branch so it uses the same integration-CI baseline as the rest of the active PR set. |
Symptom: CI failed in TestMxCheck_DoctypeScripts/empty_java_action_argument.mdl because a Java action declared as RETURNS Void was written as an entity return type named .void, and Studio Pro reported CE1613. Root cause: the generic data-type visitor treats bare qualified names as entity/enumeration references. Java action return types reused that generic path, so the explicit Void spelling became a qualified name instead of ast.TypeVoid. Fix: add a Java-action return-type wrapper that maps unqualified Void to ast.TypeVoid while leaving generic data-type parsing unchanged for parameters and attributes. Tests: added visitor coverage for explicit RETURNS Void; verified mxcli check for the doctype fixture and the targeted integration subtest that failed in GitHub Actions.
AI Code ReviewWhat Looks Good
Moderate Issues
RecommendationApprove the PR. The changes are well-implemented, follow the project's patterns, have adequate test coverage, and address the stated need. The implementation correctly wires through the full pipeline (grammar → AST → visitor → executor) and maintains backward compatibility. The minor issues don't block approval, and the benefits outweigh the concerns. The PR is scoped to a single feature (expressions in add-to-list statements) with beneficial example cleanup as a related improvement. Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
Symptom: PR mendixlabs#362 passed parser and unit tests but failed the integration mx check on add_expression_to_list.mdl with CE0117 at the generated ChangeListAction. Root cause: the CI doctype fixture used head($SourceItems) directly as a ChangeListAction.Value. Studio Pro 11.9 rejects that expression in this slot even though the MDL parser accepts list-operation syntax as a generic expression. The branch-scope validator test also switched to an if expression and exposed that exprVarRefs did not recurse through IfThenElseExpr or SourceExpr. Fix: change the doctype fixture and proposal example to an object-valued conditional expression that validates in Studio Pro, and teach exprVarRefs to recurse through IfThenElseExpr and SourceExpr so add-to-list expression references are still checked. Tests: verified mxcli check for the fixture, the targeted integration subtest TestMxCheck_DoctypeScripts/add_expression_to_list.mdl, focused add-to-list validator tests, make build, make test, and make lint-go.
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