Commit 316a8220
316a8220c758Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
codegen: Integer#times/upto/downto return self in expr position
x = 5.times { } should bind x to 5 (per MRI). The statement
form was handled at compile_block_iteration_stmt; the expression
form fell through to compile_int_method_expr's tail, emitting 0.
Route through the same compile_*_block emitters then return the receiver expression.
Refs #877
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 316a8220c758
- Parent
- 753b140c3b64
spinel_codegen.rbmodifiedView file
@@ -19880,6 +19880,20 @@
1988019880
end1988119881
end1988219882
end19883+
# Integer#times / upto / downto in expression position. The stmt19884+
# form is handled by compile_block_iteration_stmt; the expression19885+
# form needs the same loop emit but a value too -- return self19886+
# per MRI. Issue #877.19887+
if (mname == "times" || mname == "upto" || mname == "downto") && @nd_block[nid] >= 019888+
if mname == "times"19889+
compile_times_block(nid)19890+
elsif mname == "upto"19891+
compile_upto_block(nid)19892+
else19893+
compile_downto_block(nid)19894+
end19895+
return rc19896+
end1988319897
""1988419898
end1988519899
test/integer_times_as_expr.rbaddedView file
Loading diff…
test/integer_times_as_expr.rb.expectedaddedView file
Loading diff…