Commit 9c349362

9c34936257f7Merged

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

Description

analyze: a poly-ivar attr-writer call infers poly, matching the boxed value

obj.attr = v as a value yields the C assignment's result. When attr's ivar widened to poly, codegen boxes a scalar rhs, so that result is the boxed poly -- but infer reported the (scalar) rhs type, so an instance_eval/exec whose last expression is such a setter sized its result temp to mrb_int and got a sp_RbVal. Report poly when the backing ivar is poly and the rhs is scalar. Fixes bm_instance_eval.

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

Details

Commit
9c34936257f7
Parent
a3c9b7fabdb8

src/analyze_infer.cmodifiedView file

@@ -1238,7 +1238,18 @@
12381238 char base[256];
12391239 if (ln - 1 < sizeof base) {
12401240 memcpy(base, name, ln - 1); base[ln - 1] = '\0';
1241- if (comp_writer_in_chain(c, cid, base, NULL) && argc >= 1) return infer_type(c, argv[0]);
1241+ int wdefc = -1;
1242+ if (comp_writer_in_chain(c, cid, base, &wdefc) && argc >= 1) {
1243+ TyKind rhsk = infer_type(c, argv[0]);
1244+ /* codegen boxes a scalar rhs into a poly ivar slot, so the assignment
1245+ expression's C value is that boxed poly -- report poly to match. */
1246+ char wivn[258]; snprintf(wivn, sizeof wivn, "@%s", base);
1247+ int wcid = wdefc < 0 ? cid : wdefc;
1248+ int wivx = comp_ivar_index(&c->classes[wcid], wivn);
1249+ TyKind wivt = wivx >= 0 ? c->classes[wcid].ivar_types[wivx] : TY_UNKNOWN;
1250+ if (wivt == TY_POLY && rhsk != TY_POLY) return TY_POLY;
1251+ return rhsk;
1252+ }
12421253 }
12431254 }
12441255 int mi = comp_method_in_chain(c, cid, name, NULL);