Commit 0d38bda5
0d38bda5b6d9Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
Merge pull request #122 from ryanseys/rs-block-forward-anon
feat(codegen): support anonymous & block forwarding (Ruby 3.1+)
Details
- Commit
- 0d38bda5b6d9
- Parent
- ba4335ae239b
- Merge parent
- c7ce56e2a773
spinel_codegen.rbmodifiedView file
@@ -744,6 +744,17 @@
744744
@needs_proc = 1745745
return compile_proc_literal(nid)746746
end747+
# Anonymous `&` forwarding (Ruby 3.1+): `inner(&)` where the748+
# enclosing method declared `def outer(&)`. The BlockArgumentNode749+
# carries no expression, so `find_block_arg` returns -1; we forward750+
# the enclosing method's anon-block param directly.751+
blk = @nd_block[nid]752+
if blk >= 0 && @nd_type[blk] == "BlockArgumentNode" && @nd_expression[blk] < 0753+
if @current_method_block_param != ""754+
@needs_proc = 1755+
return "lv_" + @current_method_block_param756+
end757+
end747758
ba = find_block_arg(nid)748759
if ba >= 0749760
@needs_proc = 1@@ -4332,7 +4343,16 @@
43324343
if result != ""43334344
result = result + ","43344345
end4335-
result = result + @nd_name[blk]4346+
# Anonymous `&` (Ruby 3.1+) — `def m(&); inner(&); end` —4347+
# produces a BlockParameterNode with no name. Synthesize a4348+
# stable internal name so the param gets a proper `lv_` slot4349+
# and downstream lookups (find_block_param_name,4350+
# @current_method_block_param) work the same as for `&block`.4351+
bn = @nd_name[blk]4352+
if bn == ""4353+
bn = "__anon_block"4354+
end4355+
result = result + bn43364356
end43374357
end43384358
resulttest/anon_block_forward.rbaddedView file
Loading diff…