Commit 977a1562
977a1562b64cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
fix: self.class.name/new in included/reopened methods
Two related fixes:
-
X.class.namein a module method transplanted to a builtin-reopen class (Object, Array, Numeric): the analysis typedself.classas TY_CLASS (because self is TY_OBJECT in the original module scope), but codegen overrides self to TY_POLY in builtin-reopen context, making.classemitsp_poly_class_name(const char *) rather than sp_Class. TheX.class.namewrapper then tried to assign a const char * to sp_Class _cl, causing a compile error. Fix: detect the builtin-reopen override in the.class.namehandler and skip the sp_class_to_s wrapper. -
self.class.new(...)in a leaf instance method: analyze correctly resolves this toty_object(enclosing_class)at line 539, but the earlier TY_CLASS + "new" fast-path at line 418 fires first and returns TY_POLY. The enclosing-class shortcut is never reached, so the method return type is TY_POLY and the generated C hassp_RbValvssp_Node *mismatch. Fix: exclude theself.classreceiver pattern from the TY_POLY fast-path so the ty_object return at line 539 is reached.
Fixes open_class_object and self_class_new_construction tests.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 977a1562b64c
- Parent
- 55cf625b0328
src/analyze.cmodifiedView file
if (!strcmp(name, "parameters")) return TY_POLY_ARRAY; } /* TY_CLASS method dispatch -- .new on a dynamic class variable returns TY_POLY */ /* TY_CLASS method dispatch -- .new on a dynamic class variable returns TY_POLY. Exception: self.class.new(...) resolves to the enclosing class statically. */ if (recv >= 0 && rt == TY_CLASS && !strcmp(name, "new") && nt_type(nt, recv) && strcmp(nt_type(nt, recv), "ConstantReadNode") != 0 && strcmp(nt_type(nt, recv), "ConstantPathNode") != 0) return TY_POLY; strcmp(nt_type(nt, recv), "ConstantPathNode") != 0) { int _is_self_class = (nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "CallNode") && nt_str(nt, recv, "name") && !strcmp(nt_str(nt, recv, "name"), "class") && nt_ref(nt, recv, "receiver") >= 0 && nt_type(nt, nt_ref(nt, recv, "receiver")) && !strcmp(nt_type(nt, nt_ref(nt, recv, "receiver")), "SelfNode")); if (!_is_self_class) return TY_POLY; } if (recv >= 0 && rt == TY_CLASS && strcmp(name, "new") != 0) { if (argc == 0 && (!strcmp(name, "to_s") || !strcmp(name, "name") || !strcmp(name, "inspect")))src/codegen.cmodifiedView file
Loading diff…