Commit db9ce804

db9ce80450c4Merged

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

Description

Implement block-less all?/one? on value-typed arrays

%i[a b c].all? raised "undefined method 'all?' for sym_array": the block-less any?/none? arms existed but all?/one? did not, so they fell through to the unresolved-call path. For int/str/sym/float arrays the elements are never nil or false, so all? is constant true (empty array included) and one? is a length of exactly 1. The analyzer already infers these as bool. Poly arrays (which can hold nil/false) are excluded.

Fixes #1311

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

Details

Commit
db9ce80450c4
Parent
72fbbe24a1cb

spinel_codegen.rbmodifiedView file

@@ -24606,6 +24606,17 @@
2460624606 pfx = array_c_prefix(recv_type)
2460724607 return "(sp_" + pfx + "_length(" + rc + ") == 0)"
2460824608 end
24609+ # Block-less all?/one? on a value-typed array. Elements (int/str/sym/float)
24610+ # are never nil or false, so all? is always true (empty array included) and
24611+ # one? is exactly a length of 1. Restricted to these element types; poly
24612+ # arrays can hold nil/false and need per-element truthiness, handled elsewhere.
24613+ if (mname == "all?" || mname == "one?") && @nd_block[nid] < 0 && (recv_type == "int_array" || recv_type == "str_array" || recv_type == "sym_array" || recv_type == "float_array")
24614+ if mname == "all?"
24615+ return "TRUE"
24616+ end
24617+ pfx = array_c_prefix(recv_type)
24618+ return "(sp_" + pfx + "_length(" + rc + ") == 1)"
24619+ end
2460924620 if mname == "count" && @nd_arguments[nid] >= 0 && @nd_block[nid] < 0
2461024621 # count(val) — count occurrences of a specific value
2461124622 pfx = array_c_prefix(recv_type)