Commit df55a1b1
df55a1b1be41Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Array#clear/shift in expression position; arr == [] empty-literal compare
clear empties the array in place and evaluates to it (typed and poly).
shift/pop on int/float arrays return the removed element (nil sentinel
when empty). arr == [] against an empty array literal compares by
length (an array equals [] iff it is empty), avoiding the untyped-empty
mismatch.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- df55a1b1be41
- Parent
- af5bd9071c31
src/analyze.cmodifiedView file
@@ -518,7 +518,7 @@
518518
if ((!strcmp(name, "first") || !strcmp(name, "last")) && argc == 1) return rt; /* first(n)/last(n) -> subarray */519519
if (!strcmp(name, "first") || !strcmp(name, "last") ||520520
!strcmp(name, "min") || !strcmp(name, "max") ||521-
!strcmp(name, "pop")) return ty_array_elem(rt);521+
!strcmp(name, "pop") || !strcmp(name, "shift")) return ty_array_elem(rt);522522
if (!strcmp(name, "minmax")) return rt; /* [min, max], same element kind */523523
if (!strcmp(name, "join")) return TY_STRING;524524
if (!strcmp(name, "pack") && argc == 1) return TY_STRING;@@ -527,7 +527,7 @@
527527
if (!strcmp(name, "push") || !strcmp(name, "<<") || !strcmp(name, "append") ||528528
!strcmp(name, "reverse") || !strcmp(name, "sort") || !strcmp(name, "uniq") ||529529
!strcmp(name, "to_a") || !strcmp(name, "dup") || !strcmp(name, "clone") ||530-
!strcmp(name, "compact") || !strcmp(name, "flatten") ||530+
!strcmp(name, "compact") || !strcmp(name, "flatten") || !strcmp(name, "clear") ||531531
!strcmp(name, "values_at")) return rt;532532
if (!strcmp(name, "[]=")) return ty_array_elem(rt);533533
if ((!strcmp(name, "assoc") || !strcmp(name, "rassoc")) && rt == TY_POLY_ARRAY)src/codegen.cmodifiedView file
Loading diff…