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

@@ -4922,10 +4922,12 @@
49224922 end
49234923 return "int"
49244924 end
4925- # String#each_byte returns the receiver per CRuby. The block-bearing
4926- # form is handled in compile_string_method_expr; the inference rule
4927- # here is what makes `ret = "hi".each_byte { ... }` typed as string.
4928- if mname == "each_byte" || mname == "each_char"
4925+ # String#each_byte / each_char / each_line all return the receiver per
4926+ # CRuby. The block-bearing form is handled in compile_string_method_expr;
4927+ # the inference rule here is what makes `ret = "hi".each_byte { ... }`
4928+ # typed as string (and the same for the expression form of each_line,
4929+ # whose statement form already works via compile_block_iteration_stmt).
4930+ if mname == "each_byte" || mname == "each_char" || mname == "each_line"
49294931 if recv >= 0 && @nd_block[nid] >= 0
49304932 rt = infer_type(recv)
49314933 if rt == "string" || rt == "mutable_str"