`resolve_constant` returns nil for names with three or more segments

Open
#1,063 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@vinistock is already working on this.

Since Oct 21, 2026.

  • #1065 by @efegokdemir — closed without merging
  • #1080 by @vinistock — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
ruby, rust
Domain
backend

Research direction

The report reproduces the failure with Graph#resolve_constant and shows that graph[...] can resolve the same fully qualified name. Start by locating the resolver implementation and its tests, then run the relevant tests and add coverage for names with three or more segments, including the nesting cases in the reproduction. Done when those calls return the declared constants without breaking the two-segment cases.

Written by the indexing model from the issue text.

Description

Graph#resolve_constant returns nil when the name has three or more segments. Two segments resolve fine, and so does the same constant if I move a segment into the nesting.

I ran into this through archspec, which resolves call receivers with resolve_constant. Every receiver like First::Second::Third.call comes back unresolved.

Repro:

require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  gem "rubydex", "0.4.1"
end

require "tmpdir"

Dir.mktmpdir do |dir|
  path = File.join(dir, "example.rb")
  File.write(path, <<~RUBY)
    module A
      module B
        module C
          class D; end
        end
      end
    end
  RUBY

  graph = Rubydex::Graph.new
  graph.index_all([path])
  graph.resolve

  [
    ["A::B", []],
    ["A::B::C", []],
    ["A::B::C::D", []],
    ["B::C", ["A"]],
    ["B::C::D", ["A"]],
    ["C::D", ["A", "B"]]
  ].each do |name, nesting|
    puts "resolve_constant(#{name.inspect}, #{nesting.inspect}) => #{graph.resolve_constant(name, nesting)&.name.inspect}"
  end

  puts "graph[\"A::B::C::D\"] => #{graph["A::B::C::D"]&.name.inspect}"
end

Output:

resolve_constant("A::B", []) => "A::B"
resolve_constant("A::B::C", []) => nil
resolve_constant("A::B::C::D", []) => nil
resolve_constant("B::C", ["A"]) => "A::B::C"
resolve_constant("B::C::D", ["A"]) => nil
resolve_constant("C::D", ["A", "B"]) => "A::B::C::D"
graph["A::B::C::D"] => "A::B::C::D"

I expected every resolve_constant call above to return the declaration. It looks like a problem with how the name itself is resolved past its second segment, not with the nesting, but I have not dug into the resolver to confirm.

Dominant language
Rust
Stars
382
Forks
30
Avg merge
16h 57m
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Shopify/rubydex

All issues in Shopify/rubydex

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.