Commit a90aa739
a90aa739c354Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Resolve String#each_line in expression position
String#each_line with a block returns the receiver, but only the
statement form was handled. The expression form (r = s.each_line { ... }) failed to resolve -- each_line was missing from the
string-block-method-returns-self inference arm that each_char/each_byte
use, and codegen had no expression-form emitter for it. Add each_line to
that arm and emit the same line-splitting loop (with chomp: support)
that the statement form uses, returning the receiver.
The repro's final r.equal?(s) exercises String#equal?, which is a
separate unimplemented method, not part of this fix.
Fixes #1221
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- a90aa739c354
- Parent
- bfc1a95522b1
spinel_analyze.rbmodifiedView file
end return "int" end # String#each_byte returns the receiver per CRuby. The block-bearing # form is handled in compile_string_method_expr; the inference rule # here is what makes `ret = "hi".each_byte { ... }` typed as string. if mname == "each_byte" || mname == "each_char" # String#each_byte / each_char / each_line all return the receiver per # CRuby. The block-bearing form is handled in compile_string_method_expr; # the inference rule here is what makes `ret = "hi".each_byte { ... }` # typed as string (and the same for the expression form of each_line, # whose statement form already works via compile_block_iteration_stmt). if mname == "each_byte" || mname == "each_char" || mname == "each_line" if recv >= 0 && @nd_block[nid] >= 0 rt = infer_type(recv) if rt == "string" || rt == "mutable_str"spinel_codegen.rbmodifiedView file
Loading diff…
test/string_each_line_expr.rbaddedView file
Loading diff…
test/string_each_line_expr.rb.expectedaddedView file
Loading diff…