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
return "int_array" end # `n.step(...)` / `f.step(...)` without a block materialises into # a typed array. Float promotes when any operand is float. # a typed array. Float promotes when any operand is float. With a # block, the call returns the receiver (per CRuby) so the type is # the receiver's type. if rt_step == "int" || rt_step == "float" if @nd_block[nid] >= 0 return rt_step end step_is_float = (rt_step == "float") ? 1 : 0 args_id_step = @nd_arguments[nid] if args_id_step >= 0spinel_codegen.rbmodifiedView file
Loading diff…
test/int_step_expr_block.rbaddedView file
Loading diff…
test/int_step_expr_block.rb.expectedaddedView file
Loading diff…