Commit f3e805cf
f3e805cf3909Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
String#between?, String#% single arg, nullable-string operators
- between?(lo, hi) for String (strcmp bounds) and numerics.
- "fmt" % value with a single non-array argument formats it as a one-element array; the analyzer types String#% as String for any arg.
- nullable-string (NULL) handling: String#nil?,
|| fallbacktruthiness for string/float/pointer lefts, and #{nil-string} interpolates to "".
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- f3e805cf3909
- Parent
- 2aee2930b822
src/analyze.cmodifiedView file
@@ -683,6 +683,7 @@
683683
if (!strcmp(name, "respond_to?") && recv >= 0) return TY_BOOL;684684
if (!strcmp(name, "nil?") && recv >= 0 && argc == 0) return TY_BOOL;685685
if (!strcmp(name, "object_id") && recv >= 0 && argc == 0) return TY_INT;686+
if (!strcmp(name, "between?") && argc == 2 && (rt == TY_STRING || ty_is_numeric(rt))) return TY_BOOL;686687
if ((!strcmp(name, "match?") || !strcmp(name, "!~")) && recv >= 0) return TY_BOOL;687688
if (!strcmp(name, "=~") && recv >= 0 && argc == 1) {688689
const char *rrt = nt_type(nt, recv), *art = nt_type(nt, argv[0]);@@ -692,7 +693,7 @@
692693
693694
if (recv >= 0 && argc == 1 && is_arith_op(name)) {694695
if (rt == TY_STRING) {695-
if (!strcmp(name, "%") && ty_is_array(a0)) return TY_STRING; /* sprintf */696+
if (!strcmp(name, "%")) return TY_STRING; /* sprintf (array or single value) */696697
if (!strcmp(name, "+") || !strcmp(name, "*")) return TY_STRING;697698
return TY_UNKNOWN;698699
}src/codegen.cmodifiedView file
Loading diff…