Skip to content

Make definition nesting usable for constant resolution - #877

Draft
soutaro wants to merge 4 commits into
mainfrom
codex/rubydex-resolve-constant
Draft

Make definition nesting usable for constant resolution#877
soutaro wants to merge 4 commits into
mainfrom
codex/rubydex-resolve-constant

Conversation

@soutaro

@soutaro soutaro commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix Graph#resolve_constant for lexical nesting stacks containing rooted or fully qualified namespace names.

Background

When callers construct a nesting stack from Definition#lexical_nesting, explicit qualification affects constant lookup. For example:

module Foo
  module ::Bar
    CONST
  end
end

The inner frame must remain ::Bar; treating it as Bar would incorrectly resolve it relative to Foo.

Graph#resolve_constant creates a temporary Name chain from the supplied strings. Rooted and fully qualified frames can introduce parent-scope and lexical-nesting dependencies that have not yet been resolved. Previously, only the final name was resolved, so lookup could fail even when the corresponding declarations existed in the graph.

Changes

  • Add recursive constant resolution that resolves a name's lexical nesting and parent scope before resolving the name itself.
  • Use recursive resolution from the Ruby Graph#resolve_constant API.
  • Add source_name to class, module, constant, and constant-alias definitions. Unlike name, it preserves explicit source-level qualification such as Bar, Foo::Bar, or ::Bar, allowing callers to construct constant-resolution nesting stacks without inferring qualification from resolved declarations.

@soutaro
soutaro force-pushed the codex/rubydex-resolve-constant branch from 3e92550 to 305e3f1 Compare June 29, 2026 08:44
@soutaro soutaro self-assigned this Jun 30, 2026
@soutaro
soutaro force-pushed the codex/rubydex-resolve-constant branch from 305e3f1 to adc7d6a Compare July 14, 2026 03:59
Assisted-By: devx/7c3d70e1-327c-4158-8ab5-ffccba197089
Assisted-By: devx/7c3d70e1-327c-4158-8ab5-ffccba197089
Assisted-By: devx/7c3d70e1-327c-4158-8ab5-ffccba197089
Assisted-By: devx/7c3d70e1-327c-4158-8ab5-ffccba197089
@soutaro
soutaro force-pushed the codex/rubydex-resolve-constant branch from adc7d6a to 0bc9457 Compare August 10, 2026 06:18
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