fix(microflows): preserve ELSIF arms by lowering to nested IfStmt (#745)#746
Draft
mlehane1 wants to merge 1 commit into
Draft
fix(microflows): preserve ELSIF arms by lowering to nested IfStmt (#745)#746mlehane1 wants to merge 1 commit into
mlehane1 wants to merge 1 commit into
Conversation
buildIfStatement read only exprs[0]/bodies[0] and the trailing ELSE body, so every middle (ELSIF expression THEN microflowBody)* pair from the grammar was silently dropped from the written model — check and exec reported success and mx check was clean, making the data loss invisible. Mendix has no native elsif construct, so lower each ELSIF arm into a nested IfStmt in the ELSE branch of the arm before it (built innermost first) — the canonical nested-exclusive-split shape. Plain IF/ELSE builds exactly as before. Verified end-to-end: exec of the bug-test script against a fresh 11.11.0 app, DESCRIBE round-trips all arms as nested if/else, mx check 0 errors. go test ./mdl/... ./sdk/... green.
ako
approved these changes
Jul 9, 2026
ako
left a comment
Collaborator
There was a problem hiding this comment.
Approve — solid, well-scoped fix
Reviewed the diff against the codebase and ran it end-to-end. This correctly fixes the silent ELSIF-arm drop (#745).
Correctness
- The approach is the only correct one.
ast.IfStmt(ast_microflow.go:289) has onlyCondition/ThenBody/ElseBody/HasElse— no ELSIF field — and Mendix has no native elsif. Lowering each arm into a nestedIfStmtin the preceding ELSE is the canonical nested-exclusive-split shape and the only representation this AST supports. - Downstream already handles it. A nested
IfStmtinside anElseBodyis exactly what a hand-written nested if/else produces —bodyTerminates,layout.measureStatements, and the flow builder all recurse generically. No serializer/executor changes needed, correctly omitted. - Edge cases traced: plain-IF, IF/ELSE, IF/ELSIF (no else), and IF/ELSIF/ELSE all lower correctly through the innermost-first loop; the plain path produces no gratuitous nesting; no annotation regression (caller applies
s.Annotationsto the returned outer stmt as before).
Testing (ran locally)
- New
visitor_microflow_elsif_test.go(chain / no-else / plain-if regression), written failing-first: pass. Full./mdl/visitor/and./mdl/executor/: pass. Build + vet: clean. - End-to-end round-trip on a real 11.12
.mpr, both engines: exec +DESCRIBE MICROFLOWreturns all four arms (one/two/three/other) as nested if/else on modelsdk and legacy. Before the fix onlyone/othersurvived.
Checklist
Test-first ✓, bug-test mdl-examples/bug-tests/745-… (numeric-prefix convention matches) ✓, fix-issue.md symptom row ✓, atomic single-concern diff ✓.
Minor, non-blocking
- DESCRIBE renders the chain as nested
if/else, not theelsifkeyword — a faithful-but-lossy round-trip. Inherent (Mendix has no elsif) and accepted in the issue; worth a one-line note in the PR body so users aren't surprised theelsifsource doesn't come back verbatim. hasElse := … || ifCtx.ELSE() != nilis belt-and-suspenders (an ELSE always yields an extra body node) — harmless, mirrors the old fallback.
Nothing blocking. Merge once un-drafted per the #745 sign-off note.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #745.
What
buildIfStatement(mdl/visitor/visitor_microflow_statements.go) read onlyexprs[0]/bodies[0]and the trailing ELSE body, so every middle(ELSIF expression THEN microflowBody)*pair from the grammar was silently dropped from the written model —checkandexecreported success andmx checkwas clean, making the data loss invisible.Mendix has no native elsif construct, so this lowers each ELSIF arm into a nested
IfStmtin the ELSE branch of the arm before it (built innermost-first) — the canonical nested-exclusive-split shape Studio Pro users build by hand. Plain IF/ELSE builds exactly as before (regression-guarded).Validation
mdl/visitor/visitor_microflow_elsif_test.go): elsif chain preserved with conditions/bodies at each level; elsif-without-else (innermost arm has no ELSE); plain if/else unchanged (no gratuitous nesting). Written failing-first against the old visitor.mdl-examples/bug-tests/745-elsif-arms-dropped.mdl— exec against a freshmxcli new11.11.0 app, thenDESCRIBE MICROFLOW BugTestElsif.MF_Gradeshows all four arms (one/two/three/other) as a nested if/else chain with sensible auto-layout positions.mx check= 0 errors on the resulting app (Windows, mx 11.11.0).go test ./mdl/... ./sdk/...green;go vet ./mdl/...clean (grammar regenerated with ANTLR 4.13.1)..mprapps..claude/skills/fix-issue.mdper the bug-fix checklist.Opened as a draft pending maintainer sign-off on #745 per CONTRIBUTING.md.
🤖 Generated with Claude Code