Commit e24f24ab
e24f24ab8675Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Namespaced class instantiation (M::Sub.new)
A .new call whose receiver is a ConstantPathNode (M::Sub) was not resolved: analyze left it untyped and codegen emitted the unresolved- call error. Resolve the class by the final path component (nested classes register under their unqualified name) in both passes so M::Sub.new builds an instance and its methods dispatch.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- e24f24ab8675
- Parent
- 9c0a7b1db31a
src/analyze.cmodifiedView file
@@ -295,6 +295,12 @@
295295
/* Class.new(...) -> an instance of that class; built-in .new constructors */296296
if (recv >= 0 && !strcmp(name, "new")) {297297
const char *rty = nt_type(nt, recv);298+
/* a namespaced class (M::Sub) -> resolve by the final path component */299+
if (rty && !strcmp(rty, "ConstantPathNode")) {300+
const char *cn = nt_str(nt, recv, "name");301+
int ci = cn ? comp_class_index(c, cn) : -1;302+
if (ci >= 0) return ty_object(ci);303+
}298304
if (rty && !strcmp(rty, "ConstantReadNode")) {299305
const char *cn = nt_str(nt, recv, "name");300306
int ci = comp_class_index(c, cn);src/codegen.cmodifiedView file
Loading diff…