feat: allow expressions in add-to-list statements#362
feat: allow expressions in add-to-list statements#362hjotha wants to merge 3 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 |
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. |
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.
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.
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.
e15576b to
a0c3ef4
Compare
AI Code ReviewLet me review this pull request against the checklist provided in CLAUDE.md. The PR is titled "feat: allow expressions in add-to-list statements" and aims to allow microflow add-to-list statements to preserve expression-valued add items. First, I'll check the key areas of the checklist: Overlap & duplication
MDL syntax designThe PR modifies the MDL syntax for add-to-list statements:
Let me check the specific syntax design guidelines from CLAUDE.md:
Full-stack consistencyLet me check if the feature is wired through the full pipeline:
Test coverage
Security & robustness
Scope & atomicity
Code quality
Bugs & correctnessLet me look for potential issues:
Potential issues I notice:
Looking at the diff again, I don't see any changes to However, looking more carefully at the grammar change: And in the AST: For the visitor to work correctly, it would need to:
Since I don't see visitor changes in the diff, this is likely missing. But let me check if the visitor changes might be in a part of the diff that wasn't shown (the note said the diff was truncated). Actually, looking at the validation changes, they reference fb.addAddToListAction(&ast.AddToListStmt{
Value: &ast.AttributePathExpr{
Variable: "Order",
Path: []string{"Number"},
},
List: "Numbers",
})This suggests that in tests, they're directly setting the Value field, which implies the visitor must be populating it correctly in real usage. Let me think about how the visitor would work:
This logic would need to be in the visitor. Since I don't see visitor changes in the diff, but the tests and validation logic depend on Value being populated, I suspect the visitor changes might be in a part of the diff that wasn't shown in the truncated view, or perhaps they were made in a way that didn't show up in the diff I'm looking at. Actually, looking at the files changed in the diff:
I don't see any visitor files in the list of changes. This is concerning. However, let me check if the visitor changes might be implicit. Sometimes when you modify the AST, the visitor changes are straightforward and might not have been considered worth showing in the diff summary, but they should still be there. Actually, looking at the PR description: "Stores the parsed expression on Given that:
I think it's reasonable to assume the visitor was modified appropriately, even if those changes aren't visible in the diff excerpt we're looking at (possibly because the diff was truncated or the visitor changes were in a section not shown). Let me check one more thing - in the microflow builder test, they're directly constructing an AddToListStmt with a Value field, which suggests that in normal operation, the visitor would be setting this field. Actually, wait - I just realized something. The visitor changes might not be in the diff because they're in a file that wasn't included in the truncated diff. The note said: "NOTE: The diff was truncated to 80k characters. Total size: 627786 bytes." So it's very possible the visitor changes are in the part that wasn't shown. Given the evidence:
I think it's safe to assume the visitor was modified correctly. Let me check for any other potential issues: In the quick reference update: This looks good - it shows both forms. In the skill file update: Use expression-valued |
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