Skip to content

Add inheritance chain method resolution#66

Merged
dak2 merged 1 commit intomainfrom
add-inheritance-chain-method-resolution
Mar 16, 2026
Merged

Add inheritance chain method resolution#66
dak2 merged 1 commit intomainfrom
add-inheritance-chain-method-resolution

Conversation

@dak2
Copy link
Owner

@dak2 dak2 commented Mar 16, 2026

Why

When a child class inherits from a parent class (e.g., class Dog < Animal), calling a method defined in the parent on a child instance (Dog.new.speak) currently produces a false positive "undefined method" error. This is because the method resolution order (MRO) does not walk the user-defined superclass chain. This is one of the most common Ruby patterns and a significant source of false positives.

Changes

  • Add superclass_map to GlobalEnv and record parent-child relationships in enter_class()
  • Introduce ResolutionContext to aggregate resolution parameters for future extensibility
  • Extend fallback_chain() to walk the superclass chain with circular inheritance protection
  • Warn on dynamic superclass expressions (e.g., Struct.new(:name)) that cannot be tracked
  • Add unit tests (5) and integration tests (3) for inheritance resolution

Checked

  • cd core && cargo test --lib — all tests pass
  • bundle exec rake test — all tests pass

🤖 Generated with Claude Code

Previously, calling a method defined in a parent class on a child class
instance (e.g., Dog.new.speak where speak is defined in Animal) produced
a false positive "undefined method" error. This is because the method
resolution order (MRO) did not walk the superclass chain for user-defined
classes.

This commit introduces a superclass_map in GlobalEnv that records
parent-child relationships at class definition time, and extends the
MRO fallback chain to walk the superclass hierarchy including each
ancestor's included modules. Circular inheritance is safely handled
via a visited set.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dak2 dak2 force-pushed the add-inheritance-chain-method-resolution branch from c4a83b5 to 7138eb5 Compare March 16, 2026 15:39
@dak2 dak2 merged commit be316fc into main Mar 16, 2026
4 checks passed
@dak2 dak2 deleted the add-inheritance-chain-method-resolution branch March 16, 2026 15:42
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