Commit 4c7768be

4c7768be47c0Merged

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

Description

Restrict the bare all?/one? array arm to no-argument calls

The new block-less all?/one? arm for value-typed arrays also matched the argument forms (one?(2), all?(pattern)), shadowing the existing arm that counts === pattern matches and breaking [1,2,3].one?(2). Gate it on the absence of arguments so only the bare form is handled here.

Refs #1311

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

Details

Commit
4c7768be47c0
Parent
30a42a708d70

spinel_codegen.rbmodifiedView file

@@ -24629,11 +24629,14 @@
2462924629 pfx = array_c_prefix(recv_type)
2463024630 return "(sp_" + pfx + "_length(" + rc + ") == 0)"
2463124631 end
24632- # Block-less all?/one? on a value-typed array. Elements (int/str/sym/float)
24633- # are never nil or false, so all? is always true (empty array included) and
24634- # one? is exactly a length of 1. Restricted to these element types; poly
24635- # arrays can hold nil/false and need per-element truthiness, handled elsewhere.
24636- 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")
24632+ # Bare (no block, no argument) all?/one? on a value-typed array. Elements
24633+ # (int/str/sym/float) are never nil or false, so all? is always true (empty
24634+ # array included) and one? is exactly a length of 1. The argument forms
24635+ # (all?(pattern) / one?(pattern)) count `=== pattern` matches and are handled
24636+ # separately, so this must not fire when an argument is present. Restricted to
24637+ # these element types; poly arrays can hold nil/false and need per-element
24638+ # truthiness, handled elsewhere.
24639+ if (mname == "all?" || mname == "one?") && @nd_block[nid] < 0 && (@nd_arguments[nid] < 0 || get_args(@nd_arguments[nid]).length == 0) && (recv_type == "int_array" || recv_type == "str_array" || recv_type == "sym_array" || recv_type == "float_array")
2463724640 if mname == "all?"
2463824641 return "TRUE"
2463924642 end