Commit 43653560

436535602be9Merged

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

Description

codegen(promote): treat array * n as repetition when the count is poly

[nil] * n with a promote-widened poly count n was intercepted by the poly-arithmetic path (rt or operand poly -> sp_poly_mul), which has no array-receiver case and returned sp_box_int(0). The array then read back as 0 and the subsequent @arr[i] = v / @arr[i] operated on garbage.

An array receiver with * is always Array#* (repeat / join), never arithmetic, regardless of the count's type:

  • analyze infers array * n as the array's own type (not poly).
  • codegen excludes an array receiver * from the poly-arithmetic path so it reaches the repeat block, and that block accepts a poly count (unboxed via emit_int_expr).

Fixes promote-mode bundle_classd_26.

Default test 992/0/0 and optcarrot checksum 59662 unchanged.

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

Details

Commit
436535602be9
Parent
427c82862e58

src/analyze_infer.cmodifiedView file

@@ -1862,6 +1862,10 @@
18621862
18631863 /* poly receiver / poly operand: result type of operations on sp_RbVal */
18641864 if (recv >= 0 && (rt == TY_POLY || a0 == TY_POLY)) {
1865+ /* array * n is repetition (yielding the same array type), not poly
1866+ arithmetic, even when the count `n` widened to poly under promote. */
1867+ if ((ty_is_array(rt) || rt == TY_POLY_ARRAY) && !strcmp(name, "*") && argc == 1)
1868+ return rt;
18651869 /* String operators with a poly operand are NOT poly arithmetic: `str % x`
18661870 is printf formatting, `str + x` is concatenation, `str * n` is repeat --
18671871 all yield a string. Defer them to the rt==TY_STRING path below. */