Commit 7e933baf

7e933baf8dccMerged

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

Description

analyze,codegen: Integer/Float#step in expression position returns receiver

result = 1.step(5) { |x| x } previously fell through the unresolved-call path and emitted 0 — the stmt-only step handler didn't fire from compile_*_method_expr, and analyze cached the return type as int_array which then SEGV'd when used as a pointer.

Reuse the existing stmt-form emitter: the expression-position arms in compile_int_method_expr and compile_float_method_expr now call compile_block_iteration_stmt for the step shape, then return the receiver (CRuby semantics, matching how the same arm handles times / upto / downto).

Analyze: the no-block step arm shouldn't claim int_array / float_array when there's a block — the call returns the receiver in that case.

Fixes #963

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

Details

Commit
7e933baf8dcc
Parent
9aa588b48b6d

spinel_analyze.rbmodifiedView file

@@ -6297,8 +6297,13 @@
62976297 return "int_array"
62986298 end
62996299 # `n.step(...)` / `f.step(...)` without a block materialises into
6300- # a typed array. Float promotes when any operand is float.
6300+ # a typed array. Float promotes when any operand is float. With a
6301+ # block, the call returns the receiver (per CRuby) so the type is
6302+ # the receiver's type.
63016303 if rt_step == "int" || rt_step == "float"
6304+ if @nd_block[nid] >= 0
6305+ return rt_step
6306+ end
63026307 step_is_float = (rt_step == "float") ? 1 : 0
63036308 args_id_step = @nd_arguments[nid]
63046309 if args_id_step >= 0