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 end
1988119881 end
1988219882 end
19883+ # Integer#times / upto / downto in expression position. The stmt
19884+ # form is handled by compile_block_iteration_stmt; the expression
19885+ # form needs the same loop emit but a value too -- return self
19886+ # per MRI. Issue #877.
19887+ if (mname == "times" || mname == "upto" || mname == "downto") && @nd_block[nid] >= 0
19888+ if mname == "times"
19889+ compile_times_block(nid)
19890+ elsif mname == "upto"
19891+ compile_upto_block(nid)
19892+ else
19893+ compile_downto_block(nid)
19894+ end
19895+ return rc
19896+ end
1988319897 ""
1988419898 end
1988519899