Skip to content

fix: accept a bare enumeration name as a return type in exec, as check does - #1563

Open
stagknee wants to merge 1 commit into
mendixlabs:mainfrom
stagknee:fix/enum-return-type
Open

stagknee wants to merge 1 commit into
mendixlabs:mainfrom
stagknee:fix/enum-return-type

Conversation

@stagknee

Copy link
Copy Markdown
Contributor

Closes #1562.

What it fixes

returns Shop.Variant, where Shop.Variant is an enumeration, passed check but failed in exec with entity 'Shop.Variant' not found for return type. This happened for microflows, nanoflows and rules. Parameters already accepted the bare name, and so did the enum X and Enumeration(X) spellings. For rules, check itself also refused the bare form, with "a rule must return a Boolean or an enumeration, not Entity".

How

  • bareEnumerationType (cmd_microflows_helpers.go) is the parameter path's existing entity → enumeration fallback, pulled out into one helper.
    • The three parameter sites call it, with unchanged behaviour.
    • The three return-type sites (microflow, nanoflow, rule) now call it too.
    • The entity is tried first, so an entity still wins when an entity and an enumeration share a name, exactly as for parameters.
  • On the check side, validate.go retypes a rule's bare return type through declaredTypeResolver.bareEnumeration before validateRule. A name that resolves to nothing is reported as that.
  • The not-found messages now read "entity or enumeration … not found / does not exist" in check and exec, for parameters and return types alike.
  • Docs: a "Returning an Enumeration" subsection in microflow-structure.md.
  • Also included: a CHANGELOG entry (Fixed), a finding in findings/mdl-executor/, and the regression script mdl-examples/bug-tests/1562-enum-return-type.mdl.

Evidence

  • Tests: enum_return_type_test.go (mock backend, real MDL) and enum_return_type_pedapp_test.go (PedApp fixture). For each of microflow, nanoflow and rule:
    • the bare name is stored as an enumeration;
    • it equals the enum and Enumeration(...) spellings;
    • an unknown name gives the new message in check and exec;
    • a bare entity stays an entity, and an entity wins a name clash;
    • an assertAgree check/exec parity test passes, with the enumeration both already in the project and created in the same script.
  • Stored model data: the PedApp BSON for the bare spelling equals the enum spelling, with GUIDs and the name stripped.
  • Control run: with the five source files at main, 24 subtests fail with the reported symptoms. All pass with the fix.
  • Real run (Mendix 11.12.5 scratch app):
    • v0.26.0 passes check -p --references, then exec fails.
    • This branch execs the microflow, nanoflow and rule, both headerless and with mdl 1;.
    • describe prints returns enum Shop.Variant, and re-running the describe output reports "Unchanged".
    • Changing an existing returns Boolean microflow goes through the splice path.
    • mx check reports 0 errors.
  • Windows: go test ./mdl/executor/ shows the same 28 pre-existing failures as main, and the diff of the two failure lists is empty.
  • Linux (golang:1.26.6-bookworm, ANTLR 4.13.2): make grammar build test check-mdl check-findings check-conformance check-migration-reference lint-go all pass.

Not in this PR

Java actions have the same ambiguity, and it fails later there. create java action … (v: Shop.Variant) returns Shop.Variant execs, but then mx check reports CE1613, "selected entity no longer exists". Separately, list of Shop.Variant as a parameter is silently stored as a scalar enumeration. That is pre-existing behaviour on the parameter path, which this PR leaves alone.

🤖 Generated with Claude Code

A bare `returns Module.Name` is recorded by the parser as an entity
reference. exec retried it as an enumeration for parameters but not for the
return types of a microflow, a nanoflow or a rule, so a script that
`check -p --references` accepted failed with "entity 'M.E' not found for
return type". For a rule, check refused it as well ("a rule must return a
Boolean or an enumeration, not Entity").

The three create handlers now resolve a return type through the helper the
parameter path uses (entity first, then enumeration), and the rule check
applies the same retyping before validateRule. The stored return type equals
the one `returns enum M.E` stores. An unknown name now reports "entity or
enumeration 'M.X' not found for return type".

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

AI Code Review

What Looks Good

  • Thorough bug fix: The PR correctly addresses issue returns Module.Enumeration passes check but exec fails with "entity … not found for return type" #1562 by making bare enumeration names work consistently in return types (microflow, nanoflow, rule) as they already did in parameters
  • Consistent behavior: The fix mirrors the existing parameter resolution logic (entity first, then enumeration fallback) across all three flow types
  • Improved error messages: Updated to say "entity or enumeration" instead of just "entity" for better user guidance
  • Comprehensive testing: Includes unit tests with mock backend, PedApp fixture tests, regression script, and real-world validation on Mendix 11.12.5
  • Proper documentation: Added "Returning an Enumeration" subsection to microflow-structure.md with clear examples
  • Clean refactoring: Extracted repeated logic into bareEnumerationType helper function, reducing duplication
  • Maintains existing semantics: Preserves entity-wins-when-name-clashes behavior matching parameter handling
  • Verified roundtrip: Evidence shows describe output is stable and re-executable

Recommendation

Approve - The PR fully resolves the reported inconsistency between check and exec for bare enumeration return types, follows existing patterns, includes adequate testing and documentation, and maintains backward compatibility while improving error messaging. All checklist considerations have been addressed appropriately for this bug-fix scope.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

returns Module.Enumeration passes check but exec fails with "entity … not found for return type"

1 participant