Commit 4d36cf94

4d36cf9422c7Merged

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

Description

Empty array literal min/max/pop/shift return the nil sentinel

[].min/.max/.pop/.shift read nil (int? sentinel) like [].first/.last, typed as a nullable int so .inspect renders "nil".

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

Details

Commit
4d36cf9422c7
Parent
d455e732a502

src/analyze.cmodifiedView file

@@ -217,8 +217,11 @@
217217 if (rty && !strcmp(rty, "ArrayNode")) {
218218 int en = 0; nt_arr(nt, recv, "elements", &en);
219219 if (en == 0) {
220- /* first/last of an empty array is nil; carry it as a nullable int */
221- if ((!strcmp(name, "first") || !strcmp(name, "last")) && argc == 0) return TY_INT;
220+ /* first/last/min/max/pop/shift of an empty array is nil; carry it as
221+ a nullable int */
222+ if ((!strcmp(name, "first") || !strcmp(name, "last") ||
223+ !strcmp(name, "min") || !strcmp(name, "max") ||
224+ !strcmp(name, "pop") || !strcmp(name, "shift")) && argc == 0) return TY_INT;
222225 rt = TY_POLY_ARRAY;
223226 }
224227 }