Commit bbdf1712

bbdf1712c35fMerged

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

Description

Array#* repeat and Array#replace type inference

Array#* (repeat): typed and poly arrays support arr * n by emitting an inline double-loop that copies elements into a new array n times.

analyze.c: arr * int now returns the same array type (was TY_UNKNOWN). analyze.c: Array#replace also added to the array methods returning rt.

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

Details

Commit
bbdf1712c35f
Parent
bf3b9ef251c7

src/analyze.cmodifiedView file

@@ -1016,6 +1016,8 @@
10161016 }
10171017 /* array + (same kind) -> same kind */
10181018 if (!strcmp(name, "+") && ty_is_array(rt) && a0 == rt) return rt;
1019+ /* array * int -> same array type (repeat) */
1020+ if (!strcmp(name, "*") && (ty_is_array(rt) || rt == TY_POLY_ARRAY) && a0 == TY_INT) return rt;
10191021 if (ty_is_numeric(rt) && ty_is_numeric(a0))
10201022 return (rt == TY_FLOAT || a0 == TY_FLOAT) ? TY_FLOAT : TY_INT;
10211023 return TY_UNKNOWN;