Commit 65ddbe55
65ddbe5541dfMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Box forwarded super args when parent param is poly (ForwardingSuperNode)
When emit_super handles a bare super (ForwardingSuperNode), emit
emit_boxed_text for params where the parent method expects TY_POLY but
the current method has a concrete type (e.g. TY_STRING).
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 65ddbe5541df
- Parent
- 3b40e2ef750b
src/codegen.cmodifiedView file
@@ -13196,7 +13196,24 @@
1319613196
if (mi < 0) { unsupported(c, id, "super (no parent method)"); return; }1319713197
buf_printf(b, "sp_%s_%s((sp_%s *)%s", c->classes[defcls].name, mc(uname), c->classes[defcls].name, g_self);1319813198
if (ty && !strcmp(ty, "ForwardingSuperNode")) {13199-
for (int i = 0; i < s->nparams; i++) buf_printf(b, ", lv_%s", s->pnames[i]);13199+
Scope *pm = &c->scopes[mi];13200+
int n = s->nparams < pm->nparams ? s->nparams : pm->nparams;13201+
for (int i = 0; i < n; i++) {13202+
LocalVar *src = scope_local(s, s->pnames[i]);13203+
LocalVar *dst = scope_local(pm, pm->pnames[i]);13204+
TyKind st = src ? src->type : TY_UNKNOWN;13205+
TyKind dt = dst ? dst->type : TY_UNKNOWN;13206+
if (dt == TY_POLY && st != TY_POLY && st != TY_UNKNOWN) {13207+
buf_puts(b, ", ");13208+
Buf _bx; memset(&_bx, 0, sizeof _bx);13209+
buf_printf(&_bx, "lv_%s", s->pnames[i]);13210+
emit_boxed_text(c, st, _bx.p, b);13211+
free(_bx.p);13212+
}13213+
else {13214+
buf_printf(b, ", lv_%s", s->pnames[i]);13215+
}13216+
}1320013217
}1320113218
else {1320213219
emit_args_filled(c, mi, nt_ref(c->nt, id, "arguments"), ", ", b);