Commit 3b40e2ef

3b40e2ef750bMerged

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

Description

Propagate param types through ForwardingSuperNode (bare super)

Bare super (ForwardingSuperNode in Prism) implicitly forwards the current method's params to the parent method. infer_param_types was only handling explicit SuperNode with arguments, so parent method params received from super remained TY_UNKNOWN.

Fix: in infer_param_types, detect ForwardingSuperNode and directly copy each current-scope param type to the corresponding parent scope param, mirroring the implicit forwarding semantics.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
3b40e2ef750b
Parent
422245e741bf

src/analyze.cmodifiedView file

@@ -3260,12 +3260,31 @@
32603260 for (int id = 0; id < nt->count; id++) {
32613261 const char *ty = nt_type(nt, id);
32623262 if (!ty) continue;
3263- if (!strcmp(ty, "SuperNode")) {
3263+ if (!strcmp(ty, "SuperNode") || !strcmp(ty, "ForwardingSuperNode")) {
32643264 Scope *s = comp_scope_of(c, id);
32653265 if (s->class_id < 0 || !s->name) continue;
32663266 int p = c->classes[s->class_id].parent;
32673267 if (p < 0) continue;
3268- changed |= bind_call_params(c, id, comp_method_in_chain(c, p, s->name, NULL));
3268+ int pmi = comp_method_in_chain(c, p, s->name, NULL);
3269+ if (pmi < 0) continue;
3270+ if (!strcmp(ty, "ForwardingSuperNode")) {
3271+ /* bare `super` forwards all current params to parent */
3272+ Scope *pm = &c->scopes[pmi];
3273+ int n = s->nparams < pm->nparams ? s->nparams : pm->nparams;
3274+ if (pm->rest_idx >= 0 && n > pm->rest_idx) n = pm->rest_idx;
3275+ for (int k = 0; k < n; k++) {
3276+ LocalVar *src = scope_local(s, s->pnames[k]);
3277+ LocalVar *dst = scope_local(pm, pm->pnames[k]);
3278+ if (!src || !dst) continue;
3279+ TyKind at = src->type;
3280+ if (at == TY_UNKNOWN) continue;
3281+ TyKind mg = ty_unify(dst->type, at);
3282+ if (mg != dst->type) { dst->type = mg; changed = 1; }
3283+ }
3284+ }
3285+ else {
3286+ changed |= bind_call_params(c, id, pmi);
3287+ }
32693288 continue;
32703289 }
32713290 /* op-assign on an object slot: `lv OP= rhs` / `@iv OP= rhs` is an