Represent unresolved superclass as Ancestor::Partial#651
Open
Represent unresolved superclass as Ancestor::Partial#651
Conversation
When a superclass reference is unresolved (e.g. `class Foo < Bar` where Bar is never defined), the ancestor chain for Foo was silently falling back to Object's chain with Ancestors::Partial state. Bar was completely absent from the chain. Mixins handle this consistently by pushing Ancestor::Partial(name_id) when a mixin reference is unresolved. Apply the same approach for superclasses. Also update assert_ancestors_eq to compare by name string so it works uniformly for both Complete and Partial ancestor entries.
Adds rdx_class_superclass_name FFI function that walks the ancestor chain looking for an Ancestor::Partial entry and reconstructs its fully-qualified name string (handling ::Foo and Foo::Bar forms). Exposed at the Ruby level as Class#superclass_name, returning nil when the superclass is resolved or absent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
class Foo < Baris indexed andBaris never defined,Foo's ancestor chain was silently falling back to[Foo, Object, BasicObject](partial) —Barwas completely absent. This is inconsistent with how unresolved mixins are handled, which pushAncestor::Partial(name_id)as a placeholder.linearize_parent_classnow returnsAncestors::Partial([Ancestor::Partial(name_id)])instead of falling back to Object's chain.assert_ancestors_eqto compare by name string, so it works uniformly for bothCompleteandPartialancestor entries (previously panicked onAncestors::Partial).Class#superclass_nameRuby API that returns the unresolved superclass name as written in source, ornilwhen resolved or absent.Test plan
unresolved_superclass_is_represented_as_partial_ancestorverifiesclass Foo < Baryields["Foo", "Bar"]test_superclass_name_returns_nil_when_superclass_is_resolvedandtest_superclass_name_returns_name_when_superclass_is_unresolvedcargo test— all 380 tests passbundle exec ruby -Itest test/declaration_test.rb— all 23 tests passcargo clippy --all-targets -- -D warnings— clean