Two includes of superclass-nested modules leave both mixins and their constants unresolved

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
ruby, rust
Domain
backend

Research direction

Start by tracing how Rubydex resolves included modules and their constants in the fixed-point loop; the issue does not name implementation files or tests. Reproduce the example with two superclass-nested includes, then compare it with the working single-include case. Done means both mixin references and the constants read through them resolve, including when both includes appear on one line.

Written by the indexing model from the issue text.

Description

A class that includes two modules nested in its superclass's namespace leaves both mixins unresolved, and the constants read through them too. With a single include, everything resolves.

# shop.rb
class Shop
end

# rate_concept.rb
module Shop::RateConcept
  LIMIT = 3
end

# price_concept.rb
module Shop::PriceConcept
  CAP = 9
end

# synth.rb
class Shop::Synth < Shop
  include RateConcept
  include PriceConcept

  def fetch = LIMIT + CAP
end
require "rubydex"
graph = Rubydex::Graph.new
graph.index_all(Dir.glob("*.rb"))
graph.constant_references do |r|
  next if r.location.uri.start_with?("rubydex:")
  puts "#{r.class.name.split('::').last} #{r.respond_to?(:name) ? r.name : r.declaration.name} #{r.location}"
end

With rubydex 0.4.4 (arm64-darwin, Ruby 4.0.9), the output is:

UnresolvedConstantReference RateConcept   synth.rb:2:11-2:22
UnresolvedConstantReference PriceConcept  synth.rb:3:11-3:23
UnresolvedConstantReference CAP           synth.rb:5:23-5:26
UnresolvedConstantReference LIMIT         synth.rb:5:15-5:20
UnresolvedConstantReference <LIMIT>       synth.rb:5:15-5:20
ResolvedConstantReference   Shop          ...

Ruby finds each module through the superclass (Shop::RateConcept, then Shop::PriceConcept), and the method reads their constants:

$ ruby -e '...same code...; p Shop::Synth.ancestors.first(3), Shop::Synth.new.fetch'
[Shop::Synth, Shop::PriceConcept, Shop::RateConcept]
12

With only include RateConcept (and def fetch = LIMIT), the output is Shop::RateConcept and Shop::RateConcept::LIMIT, both resolved. It looks like the second mixin's resolution depends on the first one's being settled, and the fixed-point loop gives up on both instead of resolving them in order.

Writing include RateConcept, PriceConcept on one line gives the same result.

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.