Skip to content

Commit a0c3ef4

Browse files
committed
fix: use valid add-to-list expression fixture
Symptom: PR #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.
1 parent 0f3fbe3 commit a0c3ef4

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

docs/11-proposals/PROPOSAL_microflow_add_expression_to_list.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Status: Draft
77
Allow `add` microflow statements to use any expression as the value being added to a list:
88

99
```mdl
10-
add head($SourceList) to $TargetList;
10+
add if $UseFirst then $FirstItem else $SecondItem to $TargetList;
1111
```
1212

1313
The existing variable-only form remains valid:
@@ -26,7 +26,7 @@ The parser stores the add value as an expression. For compatibility, a bare vari
2626

2727
## Tests And Examples
2828

29-
`mdl-examples/doctype-tests/add_expression_to_list.test.mdl` demonstrates adding `head($SourceList)` to another list. Go regression tests cover parser behavior and builder output for both expression and simple-variable forms.
29+
`mdl-examples/doctype-tests/add_expression_to_list.mdl` demonstrates adding an object-valued conditional expression to another list. Go regression tests cover parser behavior and builder output for both expression and simple-variable forms.
3030

3131
## Open Questions
3232

mdl-examples/doctype-tests/add_expression_to_list.mdl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ create persistent entity AddListExample.Item (
55
);
66
/
77

8-
create microflow AddListExample.AddFirstItem (
9-
$SourceItems: list of AddListExample.Item
8+
create microflow AddListExample.AddChosenItem (
9+
$UseFirst: Boolean
1010
)
1111
returns list of AddListExample.Item as $Items
1212
begin
13+
$First = create AddListExample.Item (Name = 'first');
14+
$Second = create AddListExample.Item (Name = 'second');
1315
$Items = create list of AddListExample.Item;
14-
add head($SourceItems) to $Items;
16+
add if $UseFirst then $First else $Second to $Items;
1517
return $Items;
1618
end;
1719
/

mdl/executor/validate_microflow.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ func exprVarRefs(expr ast.Expression) []string {
537537
}
538538
case *ast.ParenExpr:
539539
refs = append(refs, exprVarRefs(e.Inner)...)
540+
case *ast.IfThenElseExpr:
541+
refs = append(refs, exprVarRefs(e.Condition)...)
542+
refs = append(refs, exprVarRefs(e.ThenExpr)...)
543+
refs = append(refs, exprVarRefs(e.ElseExpr)...)
544+
case *ast.SourceExpr:
545+
refs = append(refs, exprVarRefs(e.Expression)...)
540546
}
541547
return refs
542548
}

mdl/executor/validate_microflow_add_to_list_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ func TestValidateMicroflowReferencesAddExpressionValue(t *testing.T) {
1515
returns Boolean
1616
begin
1717
declare $Items List of Synthetic.Item = empty;
18+
declare $Fallback Synthetic.Item = empty;
1819
if true then
19-
declare $SourceItems List of Synthetic.Item = empty;
20+
declare $SourceItem Synthetic.Item = empty;
2021
end if;
21-
add head($SourceItems) to $Items;
22+
add if true then $SourceItem else $Fallback to $Items;
2223
return true;
2324
end;`
2425

@@ -30,7 +31,7 @@ end;`
3031

3132
violations := ValidateMicroflow(stmt)
3233
for _, violation := range violations {
33-
if violation.RuleID == "MDL005" && strings.Contains(violation.Message, "$SourceItems") {
34+
if violation.RuleID == "MDL005" && strings.Contains(violation.Message, "$SourceItem") {
3435
return
3536
}
3637
}

0 commit comments

Comments
 (0)