Skip to content

Let an enum with no registered class take any enum value - #504

Merged
dimensionscape merged 1 commit into
mainfrom
fix/enum-check-unregistered
Nov 28, 2026
Merged

dimensionscape merged 1 commit into
mainfrom
fix/enum-check-unregistered

Conversation

@dimensionscape

@dimensionscape dimensionscape commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

For 6.0.3. Fixes a regression in 6.0.2 from #492.

Main's full CI on 35cede7 failed "haxe unit" on all five platforms with the same single error:

unit.issues.Issue10830
  test: ERROR E
    Invalid Cast
Called from unit.issues.Issue10830.create (unit/issues/Issue10830.hx line 100)

Cause

#492 gave HX_DO_ENUM_RTTI _hx_isEnumValueOf, which compares a value's class with the enum's own __mClass, and it returned false when __mClass is null. An extern enum written by hand in C++, as Issue10830 does, uses HX_DO_ENUM_RTTI but never registers its class, so every value of it failed its own check. The switch in that test threw Invalid Cast, and so would a typed catch of it or a cast to it.

6.0.2 shipped with it. The haxe unit job runs only on pushes to main, and main's push runs after #492 were cancelled to free runners, so 35cede7's was the first to reach it.

Change

An enum whose __mClass is null takes any enum value again, through the clsIdEnum check every enum used before #492. Enums Haxe generates register their class, and still check for their own. The change is one expression in include/hx/Macros.h and include/hx/MacrosFixed.h, plus a sentence in the comment in include/hx/Object.h.

Tests

test/regression/EnumUnregisteredClass is Issue10830's extern enum, with a switch, a cast from Dynamic and a typed catch. It also checks that two generated enums still tell each other apart. Without the change it stops with "Invalid Cast"; with it, it prints the expected output. Run on 64-bit Windows with MSVC and Haxe 4.3.7.

Haxe 4.3.7's unit suite, which PR CI does not run, passes against this branch on 64-bit Windows with MSVC: 11025 of 11025 assertions, Issue10830 included. The branch is on main at b6981ce, so that run covers every 6.0.3 change so far.

#492 gave HX_DO_ENUM_RTTI _hx_isEnumValueOf, which compares a value's
class with the enum's own __mClass, and returned false when __mClass is
null. An extern enum written by hand in C++, as Haxe's
unit.issues.Issue10830 does, never registers its class, so every value
of it failed its own check: the switch in that test threw Invalid Cast,
and so would a typed catch of it or a cast to it. 6.0.2 shipped with it,
since the haxe unit job runs only on pushes to main.

An enum whose __mClass is null takes any enum value again, through the
clsIdEnum check every enum used before #492. Enums Haxe generates have
their class, and still check for their own.

EnumUnregisteredClass is Issue10830's extern enum, with a switch, a cast
from Dynamic and a typed catch, and checks that generated enums still
tell each other apart. It threw Invalid Cast before this change.

Tests: EnumUnregisteredClass
@dimensionscape
dimensionscape merged commit e088cf0 into main Nov 28, 2026
37 checks passed
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.

1 participant