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

@@ -1319,7 +1319,11 @@
13191319 int sc = nt_ref(nt, c->classes[i].def_node, "superclass");
13201320 if (sc < 0) continue;
13211321 const char *sty = nt_type(nt, sc);
1322- if (sty && !strcmp(sty, "ConstantReadNode")) {
1322+ /* A module-qualified superclass (`class Child < M::Handler`) is a
1323+ ConstantPathNode whose `name` is the last segment ("Handler").
1324+ Classes are registered under that bare last name, so resolve it the
1325+ same way as an unqualified ConstantReadNode superclass. */
1326+ if (sty && (!strcmp(sty, "ConstantReadNode") || !strcmp(sty, "ConstantPathNode"))) {
13231327 int p = comp_class_index(c, nt_str(nt, sc, "name"));
13241328 if (p >= 0 && p != i) c->classes[i].parent = p;
13251329 }