Constant reference unresolved inside a class nested in its own superclass when the outer namespace is only implied by compact definitions

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

Maintainers usually reply within 1 day

@efegokdemir is already working on this.

Since Oct 25, 2026.

  • #1088 by @efegokdemir — open

Assessment

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

Research direction

Start with rust/rubydex/src/resolution_tests.rs and the constant_resolution_tests helpers. Run the three reproductions to confirm the implicit namespace and own-superclass case fails while the controls pass, then trace constant resolution and the create_todo_for_parent path mentioned in #1005. Done means Record::LIMIT resolves in the failing case and the controls continue to pass; linked pull request #1088 is already open.

Written by the indexing model from the issue text.

Description

Summary

When a namespace exists only through compact definitions (class Outer::Base, with no module Outer indexed anywhere), a top-level constant reference inside class Outer::Base::Child < Outer::Base is left unresolved. The same reference resolves when either:

  • module Outer; end is also indexed, or
  • the class inherits from a sibling instead (class Outer::Base::Child < Outer::Other).

So the failure needs both: the outer namespace is implicit, and the class is nested inside its own superclass. This pattern is common in Rails apps that use Zeitwerk, where a base class's subclasses live in a directory named after it (base.rb plus base/child.rb) and the top namespace has no file of its own.

Reproduction

In rust/rubydex/src/resolution_tests.rs, inside constant_resolution_tests, using the existing helpers:

fn nested_in_superclass(explicit: bool, superclass: &str) {
    let mut context = graph_test();
    context.index_uri("file:///record.rb", "class Record\n  LIMIT = 4\nend\n");
    if explicit {
        context.index_uri("file:///outer.rb", "module Outer\nend\n");
    }
    context.index_uri("file:///base.rb", "class Outer::Base\nend\n");
    context.index_uri("file:///other.rb", "class Outer::Other\nend\n");
    context.index_uri(
        "file:///child.rb",
        &format!("class Outer::Base::Child < {superclass}\n  def limit\n    Record::LIMIT\n  end\nend\n"),
    );
    context.resolve();
    assert_constant_reference_to!(context, "Record", "file:///child.rb:3:5-3:11");
}

#[test]
fn nested_in_own_superclass_implicit_namespace() {
    nested_in_superclass(false, "Outer::Base"); // fails
}

#[test]
fn nested_in_own_superclass_explicit_namespace() {
    nested_in_superclass(true, "Outer::Base"); // passes
}

#[test]
fn other_superclass_implicit_namespace() {
    nested_in_superclass(false, "Outer::Other"); // passes
}

On v0.4.2 (c69a742), the first test fails in both the resolution::tests and operation::applier::resolution_tests copies:

Reference to found at `file:///child.rb:3:5-3:11` is unresolved

The other two pass. main (b553f94, v0.4.3) has no source changes since v0.4.2, so the behaviour is the same there.

Expected

Record resolves to the top-level Record. At runtime (Ruby 4.0.5), once Outer exists (from a loader or any file), the method returns 4:

module Outer; end
class Record; LIMIT = 4; end
class Outer::Base; end
class Outer::Base::Child < Outer::Base; def limit = Record::LIMIT; end
p Outer::Base::Child.new.limit # => 4

The lexical scope of a compact class Outer::Base::Child is only Outer::Base::Child itself, so lookup goes through its ancestors (Outer::Base, then Object) and finds Record on Object.

Related

  • #1005 gave compact-only namespaces an ancestors unit (create_todo_for_parent); it is in v0.4.2, and this case still fails. It may be a remaining ordering gap on the same path: the superclass Outer::Base is also the child's lexical parent, under a namespace that starts as a TodoDeclaration.
  • #997 is about loader-created namespaces changing which declaration a name refers to. This report is different: every name here has a single definition, and the reference resolves to nothing.

Found while running a transpiler over a large real app. Six references in one file of that app hit this.

🤖 Generated with Claude Code

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.