Skip to content

Fix class-implements-interface optional-member crash and add coverage#279

Merged
ASDAlexander77 merged 2 commits into
mainfrom
fix/class-implements-interface-optional-crash
Jul 22, 2026
Merged

Fix class-implements-interface optional-member crash and add coverage#279
ASDAlexander77 merged 2 commits into
mainfrom
fix/class-implements-interface-optional-crash

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes a real crash: class X implements Interface crashed the compiler at DECLARATION time (no instantiation needed) whenever Interface had an optional member (opt?: number) that X didn't declare. mlirGenClassVirtualTableDefinitionForInterface never checked the isMissing flag that getVirtualTable already provides for this legitimate case, unlike its object-literal sibling (mlirGenObjectVirtualTableDefinitionForInterface), which already handles it correctly with a -1 sentinel placeholder. Fixed by mirroring that existing, proven handling.
  • Adds cross-module (export/import) test coverage for class+interface combinations with no prior coverage: multilevel interface extends implemented by a class, optional interface members implemented by a class, an abstract class implementing an interface, and structural (no explicit implements) interface satisfaction (a different code path: mlirGenCreateInterfaceVTableForClass, triggered at cast time, vs. the declaration-time mlirGenClassHeritageClauseImplements path).
  • Fixes the dynamic-import link failure: a class casting itself (not just a subclass) to one of its own interfaces from the importing module failed to link with "undefined symbol" - mlirGenClassVirtualTableDefinitionForInterface always emitted a constant SymbolRefOp for the implementing method, unlike the class's ordinary vtable builder, which already resolves a dynamic-import-owned method at runtime instead (SearchForAddressOfSymbolOp). Mirroring that fix exposed two further, general (not interface-specific) lowering-pass bugs - both GlobalOpLowering and createFunctionFromRegion were giving a synthesized __cctor constructor function the wrong debug-info location when its initializer is lazily rebuilt from inside an unrelated function - both fixed. This re-enables the multilevel, optional, and structural-interface -shared tests.
  • One tier remains disabled: the abstract-class variant surfaces a separate, unrelated bug - an inherited concrete method's internal virtual call (this.area()) returns a wrong value when the method is reached through an interface reference (works correctly via direct or base-class-typed calls). Documented in detail in CMakeLists.txt and left for a dedicated follow-up.

Test plan

  • Minimal single-file repro of the optional-member crash - fixed, verified via --emit=obj
  • ctest -C Debug -R "implements-interface|structural-interface" - all enabled tiers pass (10/10)
  • Full suite: ctest -C Debug -j8 - 786/786 passed, no regressions

class X implements Interface crashed the compiler at declaration time
(no instantiation needed) whenever Interface had an optional member X
didn't declare - mlirGenClassVirtualTableDefinitionForInterface never
checked the isMissing flag that getVirtualTable already provides,
unlike its object-literal sibling
(mlirGenObjectVirtualTableDefinitionForInterface), which already
handles this correctly. Fixed by mirroring that existing handling.

Also adds cross-module (export/import) test coverage for class+interface
combinations that had no prior coverage: multilevel interface extends,
optional interface members, abstract class implementing an interface,
and structural (no explicit `implements`) interface satisfaction. Several
-shared tiers are added but left disabled in CMakeLists.txt, documented
with the root cause: a class that is itself a dynamic import gets a
constant (unresolvable) symbol reference for methods reachable only
through its own interface vtable, when cast to that interface from the
importing module - a real, separate, deeper bug left for a follow-up.
@ASDAlexander77
ASDAlexander77 merged commit 71a1b7b into main Jul 22, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix/class-implements-interface-optional-crash branch July 22, 2026 17:24
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