Commit af5bd907
af5bd9071c31Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Array#at (nullable element); float/string == nil sentinel comparison
Array#at(i) aliases [i] (sp_*Array_get already returns the nil sentinel
on out-of-range and handles negatives), typed as the element type so the
sentinel surfaces. Extend x == nil to recognize the float NaN sentinel
and the NULL string sentinel, matching the existing int case.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- af5bd9071c31
- Parent
- c23e4b232537
src/analyze.cmodifiedView file
@@ -509,6 +509,7 @@
509509
if (argc == 1 && nt_type(nt, argv[0]) && !strcmp(nt_type(nt, argv[0]), "RangeNode")) return rt;510510
return ty_array_elem(rt);511511
}512+
if (!strcmp(name, "at") && argc == 1) return ty_array_elem(rt); /* like [i] */512513
/* index returns nil on a miss -> poly (int-or-nil) */513514
if (!strcmp(name, "index") && (rt == TY_INT_ARRAY || rt == TY_STR_ARRAY)) return TY_POLY;514515
if (!strcmp(name, "length") || !strcmp(name, "size") ||src/codegen.cmodifiedView file
Loading diff…