Skip to content

Fix constant resolution to prioritize nesting scope over Object ancestors#395

Merged
mame merged 1 commit intoruby:masterfrom
sinsoku:fix-const-resolution-nesting-priority
Feb 26, 2026
Merged

Fix constant resolution to prioritize nesting scope over Object ancestors#395
mame merged 1 commit intoruby:masterfrom
sinsoku:fix-const-resolution-nesting-priority

Conversation

@sinsoku
Copy link
Contributor

@sinsoku sinsoku commented Feb 25, 2026

In Ruby's constant lookup, lexical scope (nesting) takes priority over
ancestors. However, resolve searched all ancestors including Object
before checking outer nesting scopes. This caused include Store inside
ActiveRecord::Base to resolve to ::Store (app model, via Object)
instead of ActiveRecord::Store (via nesting).

Stop ancestor search at Object when outer nesting scopes remain to be
checked (cref.outer), while preserving existing behavior for
ScopedConstRead which already passes break_object=true.

…tors

In Ruby's constant lookup, lexical scope (nesting) takes priority over
ancestors. However, `resolve` searched all ancestors including Object
before checking outer nesting scopes. This caused `include Store` inside
`ActiveRecord::Base` to resolve to `::Store` (app model, via Object)
instead of `ActiveRecord::Store` (via nesting).

Stop ancestor search at Object when outer nesting scopes remain to be
checked (cref.outer), while preserving existing behavior for
ScopedConstRead which already passes break_object=true.
Copy link
Member

@mame mame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mame mame merged commit 188acee into ruby:master Feb 26, 2026
7 checks passed
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.

2 participants