Commit b1a0f05f

b1a0f05fa17bMerged

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

Description

Add bool#===, Range#==/#eql?, and Range#each without a block

Three small comparison/iteration gaps:

  • TrueClass#=== / FalseClass#=== (case equality): true only when the argument is a boolean with the same value; a non-boolean is never ===.
  • Range#== / #eql?: compare first, last, and exclusivity via a new sp_range_eq helper (sp_Range is a value-type struct, so plain C == was invalid). compile_eq grows a range case alongside class/encoding/ time; a range only equals another range.
  • Range#each without a block: materialize the element array (int_array) so .to_a / chaining work, matching the #to_a lowering.

analyze types ===/eql? as bool and a block-less range each as int_array.

Fixes #1293 Fixes #1296 Fixes #1297

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

Details

Commit
b1a0f05fa17b
Parent
b16a6e1c51f1

lib/sp_runtime.hmodifiedView file

@@ -222,6 +222,7 @@
222222 #include "sp_core.h"
223223
224224 static sp_Range sp_range_new(mrb_int f,mrb_int l,mrb_int e){sp_Range r;r.first=f;r.last=l;r.excl=e;return r;}
225+static mrb_bool sp_range_eq(sp_Range a,sp_Range b){return a.first==b.first&&a.last==b.last&&a.excl==b.excl;}
225226 /* `Range#include?`/`#cover?` on the boxed (SP_TAG_OBJ cls_id
226227 SP_BUILTIN_RANGE) Range value. The direct sp_Range typed path
227228 inlines this same check via compile_range_method_expr; poly-recv