Constant reference unresolved inside a class nested in its own superclass when the outer namespace is only implied by compact definitions
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Domain
- backend, developer-experience
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; endis 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 superclassOuter::Baseis also the child's lexical parent, under a namespace that starts as aTodoDeclaration. - #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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Shopify/rubydex
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
`self.private :foo` is reported as an invalid visibility call and ignoredPossibly taken @RaphaelFakhri claimed this 30 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Expose comment groups that aren't attached to a definitionPossibly taken @efegokdemir claimed this 31 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
Incorrect resolved superclass namePossibly taken @efegokdemir claimed this 38 days ago. Openbug roundhouse
Difficulty 4/5 1-2 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
`resolve_constant` returns nil for names with three or more segmentsPossibly taken @vinistock claimed this 33 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 65/100
Maintainers usually reply within 1 day
Similar issues
-
CI/CD ignore-for-release
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
eclipse-ankaios/ankaios#844 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
std: `SliceIndex<str>` missing for `std::ops` ranges, so generic `R: SliceIndex<str>` bounds failOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
symposium-dev/symposium#530 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day