Commit d0ab33a3

d0ab33a36686Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

method / callee and String#clone

method and callee resolve to the enclosing method's name as a symbol (nil at the top level); the name is interned during analyze so the symbol id table is sized before the codegen prologue. String#clone aliases dup.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
d0ab33a36686
Parent
18961858e1de

src/analyze.cmodifiedView file

@@ -252,6 +252,11 @@
252252 if (!strcmp(name, "parameters")) return TY_POLY_ARRAY;
253253 }
254254
255+ /* __method__ / __callee__ -> the enclosing method's name (a symbol) */
256+ if (recv < 0 && argc == 0 &&
257+ (!strcmp(name, "__method__") || !strcmp(name, "__callee__")))
258+ return TY_SYMBOL;
259+
255260 /* identity methods: return the receiver unchanged */
256261 if (recv >= 0 && argc == 0 &&
257262 (!strcmp(name, "freeze") || !strcmp(name, "itself") ||
@@ -2347,6 +2352,15 @@
23472352 const char *v = nt_str(c->nt, id, "value");
23482353 if (v) comp_sym_intern(c, v);
23492354 }
2355+ /* __method__ / __callee__ yield the enclosing method's name as a symbol;
2356+ intern it now so the id table is sized before the codegen prologue */
2357+ else if (ty && !strcmp(ty, "CallNode") && nt_ref(c->nt, id, "receiver") < 0) {
2358+ const char *nm = nt_str(c->nt, id, "name");
2359+ if (nm && (!strcmp(nm, "__method__") || !strcmp(nm, "__callee__"))) {
2360+ Scope *s = comp_scope_of(c, id);
2361+ if (s && s->name && s->name[0]) comp_sym_intern(c, s->name);
2362+ }
2363+ }
23502364 }
23512365 /* Proc#parameters reports param kinds (:req/:opt) and names as symbols;
23522366 intern them now so they land in the table before the codegen prologue. */