Skip to content

Give a class without a constructor over a host class the one Haxe generates - #53

Open
Tutez64 wants to merge 1 commit into
MeguminBOT:mainfrom
Tutez64:bugfix/cppia-implicit-new-chain
Open

Tutez64 wants to merge 1 commit into
MeguminBOT:mainfrom
Tutez64:bugfix/cppia-implicit-new-chain

Conversation

@Tutez64

@Tutez64 Tutez64 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

A script class that declares no constructor, directly over a host class, now gets the constructor Haxe generates for it.

hxcpp hands a cppia class without a new its base's constructor only when that base is a cppia class too (CppiaClassInfo::linkTypes). Haxe's own cppia never relies on that, since it always writes the inherited constructor. The emitter did not, so for class Mid extends HostBase {}:

  • new Mid() never ran the host's constructor: every field it sets read null or zero, silently;
  • a subclass's super(), explicit or the implicit one an initialiser brings, dereferenced the null constructor while linking (CallMember::linkSuperCall) and ended the process, with or without the JIT.

settleImplicitConstructors now also gives such a class the forwarding constructor it already wrote for a class with member initialisers. Only a class whose direct base is a host class gets one: over a script class, hxcpp's inherited constructor is already right, so no call is added there.

Before After
new Mid().made (set by HostBase's constructor) compiled, null compiled, host
new Sub(), Sub extends Mid with new() super() segfault while loading compiled, host
new Sub(), Sub extends Mid with an initialiser segfault while loading compiled, host5

A host base whose constructor shape is unknown refuses the module, as it already did for a class with initialisers; the message no longer mentions initialisers.

Tests

  • Three corpus cases, over a new made field on the HostBase fixture, set by its constructor. Without the fix, the first fails in the cppia suite (cppia gave null, interpreter gave host) and the second ends it.
  • test/run.sh eval cpp on hxcpp master: 421 / 421 / 454. Conformance columns are unchanged apart from the three new rows, compiled in both cppia columns.
  • Flixel sandbox (flixel, openfl, lime, plain, JIT on and off): same modules compiled, same byte counts, same two left interpreted (Playground, Shapes) as the baseline.

…ne Haxe generates.

hxcpp hands a cppia class without a `new` its base's constructor only when that
base is a cppia class. Over a host class it had none: `new` skipped the host's
constructor, and a subclass's `super()` crashed the cppia link. Such a class now
gets the forwarding constructor a class with member initialisers already got;
over a script base nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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