Commit 607588a0

607588a0ea0bMerged

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

Description

analyze(promote): follow an int constant to poly when its initializer widened

A COUNT = R.new.take(mk) whose method return widened to poly (step 3) kept its int constant slot, so codegen emitted mrb_int cst_COUNT = <sp_RbVal>. Mirror the local-follow step (4) for constants: re-derive an int constant's type from its initializer to poly when that value now infers poly. Fixes bare_module_body_cmethod_call.

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

Details

Commit
607588a0ea0b
Parent
138302d3ddc8

src/analyze.cmodifiedView file

@@ -2390,6 +2390,20 @@
23902390 if (vnode < 0) continue;
23912391 if (infer_type(c, vnode) == TY_POLY_ARRAY) { lv->type = TY_POLY_ARRAY; changed = 1; }
23922392 }
2393+ /* (5) a constant assigned from a value that widened to poly (a method
2394+ return widened in step 3, an int constant assigned an arithmetic
2395+ result, ...) must follow: a `COUNT = obj.m` whose method now returns
2396+ poly otherwise mismatches the int constant slot. */
2397+ for (int id = 0; id < nt->count; id++) {
2398+ const char *ty = nt_type(nt, id);
2399+ if (!ty || strcmp(ty, "ConstantWriteNode")) continue;
2400+ const char *nm = nt_str(nt, id, "name");
2401+ LocalVar *cv = nm ? comp_const(c, nm) : NULL;
2402+ if (!cv || cv->type != TY_INT) continue;
2403+ int vnode = nt_ref(nt, id, "value");
2404+ if (vnode < 0) continue;
2405+ if (infer_type(c, vnode) == TY_POLY) { cv->type = TY_POLY; changed = 1; }
2406+ }
23932407 }
23942408 /* refresh the node-type cache so a `proc.call` node picks up the updated
23952409 proc_ret (codegen reads comp_ntype, not lv->proc_ret directly). Re-infer