Skip to content

Add module include support for mixin method resolution#57

Merged
dak2 merged 1 commit intomainfrom
add-module-include-support
Mar 13, 2026
Merged

Add module include support for mixin method resolution#57
dak2 merged 1 commit intomainfrom
add-module-include-support

Conversation

@dak2
Copy link
Owner

@dak2 dak2 commented Mar 13, 2026

Summary

  • Add include detection in dispatch.rs to recognize module mixin declarations (single, multiple, qualified names)
  • Track module inclusions in GlobalEnv via module_inclusions: HashMap<String, Vec<String>>
  • Extend MethodRegistry::fallback_chain to search included modules between the class and Object, following Ruby's MRO (last included module has highest priority)
  • Add 8 Rust integration tests and 6 Ruby integration tests covering basic include, multiple modules, qualified names, simultaneous include, MRO priority, and error detection

Why

include Greetable was previously treated as an unknown implicit self method call, producing false TypeError on methods defined in included modules. This is a fundamental Ruby pattern that must be supported for practical type checking.

Test plan

  • Rust unit tests: MethodRegistry resolve with inclusions, MRO order, class priority over include, include before Object
  • Rust integration tests: basic include, return type inference, multiple modules, class method priority, qualified modules, simultaneous include, unknown module safety, simultaneous include order
  • Ruby integration tests: basic no error, receiverless call, multiple modules, simultaneous include, qualified module, method type error detection
  • cd core && cargo test --lib — all tests pass
  • bundle exec rake test — all tests pass

🤖 Generated with Claude Code

Previously, `include` was treated as an implicit self method call,
causing false type errors when calling methods defined in included
modules (e.g., `User.new.greet` where `greet` is from `Greetable`).

This adds mixin tracking to GlobalEnv and extends the MRO fallback
chain to search included modules between the class itself and Object,
matching Ruby's method resolution order semantics.

Supports: single/multiple includes, qualified module names (A::B),
simultaneous include (include A, B), and correct MRO priority.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dak2 dak2 merged commit 7c7725a into main Mar 13, 2026
2 checks passed
@dak2 dak2 deleted the add-module-include-support branch March 13, 2026 11:02
@dak2 dak2 mentioned this pull request Mar 15, 2026
4 tasks
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