Commit 6191a06e
6191a06ecdbaMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
Resolve a module-qualified superclass for bare super
A bare super (ForwardingSuperNode) walks c->classes[child].parent to
find the parent method. resolve_parents only set .parent when the
superclass node was an unqualified ConstantReadNode, so class Child < M::Handler (a ConstantPathNode) left .parent at -1 and super failed
with "no parent method" -- even though the unqualified form worked.
A ConstantPathNode reports its last path segment as name ("Handler"),
and nested classes are already registered under that bare last name, so
resolving it through comp_class_index the same way as a ConstantReadNode
superclass is sufficient. This matches how the builtin-exception ancestry
check already treats the two node types.
Fixes #1413
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 6191a06ecdba
- Parent
- 3a7546670ef2
src/analyze_scope.cmodifiedView file
int sc = nt_ref(nt, c->classes[i].def_node, "superclass"); if (sc < 0) continue; const char *sty = nt_type(nt, sc); if (sty && !strcmp(sty, "ConstantReadNode")) { /* A module-qualified superclass (`class Child < M::Handler`) is a ConstantPathNode whose `name` is the last segment ("Handler"). Classes are registered under that bare last name, so resolve it the same way as an unqualified ConstantReadNode superclass. */ if (sty && (!strcmp(sty, "ConstantReadNode") || !strcmp(sty, "ConstantPathNode"))) { int p = comp_class_index(c, nt_str(nt, sc, "name")); if (p >= 0 && p != i) c->classes[i].parent = p; }test/super_qualified_superclass.rbaddedView file
Loading diff…
test/super_qualified_superclass.rb.expectedaddedView file
Loading diff…