Skip to content

Fix singleton class ancestor chain for intermediate classes#709

Merged
st0012 merged 1 commit into
mainfrom
fix-singleton-ancestor-chain
Mar 31, 2026
Merged

Fix singleton class ancestor chain for intermediate classes#709
st0012 merged 1 commit into
mainfrom
fix-singleton-ancestor-chain

Conversation

@st0012
Copy link
Copy Markdown
Member

@st0012 st0012 commented Mar 31, 2026

Fixes #708

Summary

  • def self.method definitions are now processed in the convergence loop instead of handle_remaining_definitions
  • get_or_create_singleton_class pushes Unit::Ancestors for newly created singletons, triggering upward cascade through the inheritance chain

Ruby creates singleton classes on demand and cascades upward — when Baz.singleton_class is accessed, Bar.singleton_class and Foo.singleton_class are created too. The problem was that singleton creation happened in handle_remaining_definitions (after the convergence loop), so Unit::Ancestors items pushed by get_or_create_singleton_class were never processed. Moving def self.method into the convergence loop lets the cascade happen naturally.

@st0012 st0012 self-assigned this Mar 31, 2026
Process `def self.method` definitions in the convergence loop instead of
handle_remaining_definitions. This ensures get_or_create_singleton_class
runs while Unit::Ancestors items can still be processed, allowing the
singleton ancestor chain to cascade upward through parent classes.

Previously, a class with no singleton definitions (e.g., `class Bar < Foo`
with no `def self.`) never got a `Bar::<Bar>` singleton, breaking the
ancestor chain for `Baz::<Baz>` → `Bar::<Bar>` → `Foo::<Foo>`.
@st0012 st0012 force-pushed the fix-singleton-ancestor-chain branch from a316f20 to e142708 Compare March 31, 2026 17:01
@st0012 st0012 marked this pull request as ready for review March 31, 2026 17:02
@st0012 st0012 requested a review from a team as a code owner March 31, 2026 17:02
@st0012 st0012 merged commit 216f6b4 into main Mar 31, 2026
36 checks passed
@st0012 st0012 deleted the fix-singleton-ancestor-chain branch March 31, 2026 20:49
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.

Singleton class ancestor chain is broken when intermediate classes have no singleton definitions

2 participants