Skip to content

Commit ff795f7

Browse files
committed
fix: emit merge flow for explicitly empty ELSE bodies
Symptom: an IF statement with a continuing THEN branch and an explicit but empty ELSE branch could build a split/merge graph without a configured false outgoing flow, causing Studio Pro CE0079. Root cause: the IF builder only connected non-returning ELSE branches to the merge when the ELSE body produced a last activity ID. An explicitly empty ELSE has HasElse=true but no lastElseID, so the false case was dropped. Fix: when an explicit empty ELSE still requires a merge, emit a direct split-to-merge flow with case false, mirroring the existing empty-THEN handling. Tests: go test ./mdl/executor -run TestIfEmptyElseBodyWithContinuingThenEmitsFalseFlowToMerge -v; make build; make test; make lint-go.
1 parent cb40add commit ff795f7

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

mdl/executor/cmd_microflows_builder_control.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
272272
}
273273
applyUserAnchors(flow, originAnchor, destAnchor)
274274
fb.flows = append(fb.flows, flow)
275+
} else {
276+
// Explicit empty ELSE body: the split still needs a configured
277+
// false case when both branches converge at the merge.
278+
flow := newDownwardFlowWithCase(splitID, mergeID, "false")
279+
applyUserAnchors(flow, falseBranchAnchor, falseBranchAnchor)
280+
fb.flows = append(fb.flows, flow)
275281
}
276282
} else if elseReturns && needMerge {
277283
fb.addPendingErrorHandlerFlowTo(mergeID)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package executor
4+
5+
import (
6+
"testing"
7+
8+
"github.com/mendixlabs/mxcli/mdl/ast"
9+
"github.com/mendixlabs/mxcli/sdk/microflows"
10+
)
11+
12+
// TestIfEmptyElseBodyWithContinuingThenEmitsFalseFlowToMerge is a regression
13+
// guard for CE0079 ("The 'false' condition value should be configured in
14+
// properties for an outgoing flow").
15+
//
16+
// Pattern: an IF with THEN that continues and an explicitly empty ELSE body.
17+
// Both branches must feed a merge, but an empty ELSE has no lastElseID to wire.
18+
func TestIfEmptyElseBodyWithContinuingThenEmitsFalseFlowToMerge(t *testing.T) {
19+
fb := &flowBuilder{
20+
spacing: HorizontalSpacing,
21+
measurer: &layoutMeasurer{},
22+
}
23+
24+
fb.addIfStatement(&ast.IfStmt{
25+
Condition: &ast.VariableExpr{Name: "Flag"},
26+
ThenBody: []ast.MicroflowStatement{
27+
&ast.LogStmt{Level: ast.LogInfo, Message: &ast.LiteralExpr{Kind: ast.LiteralString, Value: "in-then"}},
28+
},
29+
// The source had an explicit ELSE token, but no statements in that
30+
// branch. That must still build a false split->merge flow.
31+
HasElse: true,
32+
})
33+
34+
var split *microflows.ExclusiveSplit
35+
var merge *microflows.ExclusiveMerge
36+
for _, obj := range fb.objects {
37+
switch o := obj.(type) {
38+
case *microflows.ExclusiveSplit:
39+
split = o
40+
case *microflows.ExclusiveMerge:
41+
merge = o
42+
}
43+
}
44+
if split == nil {
45+
t.Fatal("expected ExclusiveSplit to be created")
46+
}
47+
if merge == nil {
48+
t.Fatal("expected ExclusiveMerge to be created")
49+
}
50+
51+
var hasFalseFlow bool
52+
for _, flow := range fb.flows {
53+
if flow.OriginID != split.ID || flow.DestinationID != merge.ID {
54+
continue
55+
}
56+
if ec, ok := flow.CaseValue.(microflows.EnumerationCase); ok && ec.Value == "false" {
57+
hasFalseFlow = true
58+
}
59+
}
60+
if !hasFalseFlow {
61+
t.Fatal("missing split->merge flow with case \"false\"")
62+
}
63+
}

0 commit comments

Comments
 (0)