Commit 76a58f19
76a58f19e983Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Return self from String#chars/bytes/codepoints/lines block form
With a block these enumerators must yield each element and return the receiver (self), but the expression-position codegen built and returned the element array while ignoring the block entirely (so the block never ran). Add a block-sensitive path that builds the array, iterates it yielding each element, and returns self. The no-block form still returns the array.
Fixes #1218
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 76a58f19e983
- Parent
- c1cd009db5b3
spinel_analyze.rbmodifiedView file
@@ -5239,6 +5239,16 @@
52395239
if mname == "split"52405240
return "str_array"52415241
end5242+
# `chars`/`bytes`/`codepoints`/`lines` with a block yield each element5243+
# and return the receiver (self), not the element array.5244+
if @nd_block[nid] >= 0 && (mname == "chars" || mname == "bytes" || mname == "codepoints" || mname == "lines")5245+
if recv >= 05246+
rt_sb = infer_type(recv)5247+
if rt_sb == "string" || rt_sb == "mutable_str"5248+
return "string"5249+
end5250+
end5251+
end52425252
if mname == "lines"52435253
return "str_array"52445254
endspinel_codegen.rbmodifiedView file
Loading diff…
test/string_enum_block_returns_self.rbaddedView file
Loading diff…
test/string_enum_block_returns_self.rb.expectedaddedView file
Loading diff…