Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions mdl-examples/bug-tests/263-nested-caption-preservation.mdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- ============================================================================
-- Bug #263: Preserve decision/loop captions across nested control flow
-- ============================================================================
--
-- Symptom (before fix):
-- `@caption` on an outer IF/LOOP/WHILE was being overwritten by the inner
-- IF/LOOP's caption because `pendingAnnotations` was shared mutable state
-- across recursive addStatement calls. Annotations attached to the outer
-- split ended up bound to the inner split, and the outer split inherited
-- whatever caption the inner statement carried.
--
-- After fix:
-- addIfStatement / addLoopStatement / addWhileStatement snapshot + clear
-- `pendingAnnotations` before recursing, then re-apply to their own activity
-- after it's created. The WHILE case also gained explicit handling in
-- mergeStatementAnnotations (previously fell through to `default: nil`).
--
-- Usage:
-- mxcli exec mdl-examples/bug-tests/263-nested-caption-preservation.mdl -p app.mpr
-- Open in Studio Pro — each split/loop displays its own caption, not
-- inherited from a nested statement.
-- ============================================================================

create module BugTest263;

create microflow BugTest263.MF_NestedCaptions (
$S: string
)
returns boolean as $ok
begin
declare $ok boolean = false;

@caption 'String not empty?'
if $S != empty then
@caption 'Right format?'
if isMatch($S, 'x') then
return true;
else
return false;
end if;
else
return false;
end if;
end;
/
22 changes: 20 additions & 2 deletions mdl/executor/cmd_microflows_builder_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func getStatementAnnotations(stmt ast.MicroflowStatement) *ast.ActivityAnnotatio
return s.Annotations
case *ast.LoopStmt:
return s.Annotations
case *ast.WhileStmt:
return s.Annotations
case *ast.LogStmt:
return s.Annotations
case *ast.CallMicroflowStmt:
Expand Down Expand Up @@ -116,8 +118,8 @@ func (fb *flowBuilder) applyAnnotations(activityID model.ID, ann *ast.ActivityAn
continue
}

// @caption, @color, and @excluded — only applicable to ActionActivity
if activity, ok := obj.(*microflows.ActionActivity); ok {
switch activity := obj.(type) {
case *microflows.ActionActivity:
if ann.Caption != "" {
activity.Caption = ann.Caption
activity.AutoGenerateCaption = false
Expand All @@ -128,6 +130,22 @@ func (fb *flowBuilder) applyAnnotations(activityID model.ID, ann *ast.ActivityAn
if ann.Excluded {
activity.Disabled = true
}
case *microflows.ExclusiveSplit:
// Splits carry a human-readable Caption (e.g. "Right format?")
// independent of the expression/rule being evaluated.
if ann.Caption != "" {
activity.Caption = ann.Caption
}
case *microflows.InheritanceSplit:
if ann.Caption != "" {
activity.Caption = ann.Caption
}
case *microflows.LoopedActivity:
// LOOP / WHILE activities can carry a caption just like
// splits and action activities.
if ann.Caption != "" {
activity.Caption = ann.Caption
}
}

break
Expand Down
Loading