Commit 311d75c9

311d75c91241Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified

Description

analyze,codegen: String#each_char as expression returns receiver

s = "hello".each_char {} used to assign 0 because the expression-level path for each_char wasn't wired up — only the statement-level loop was. Add the same loop in compile_string_method_expr returning the receiver, and have the analyzer infer the return type as the receiver type.

Fixes #866

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
311d75c91241
Parent
4d7c5ef3aafb

spinel_analyze.rbmodifiedView file

@@ -4339,7 +4339,7 @@
43394339 # String#each_byte returns the receiver per CRuby. The block-bearing
43404340 # form is handled in compile_string_method_expr; the inference rule
43414341 # here is what makes `ret = "hi".each_byte { ... }` typed as string.
4342- if mname == "each_byte"
4342+ if mname == "each_byte" || mname == "each_char"
43434343 if recv >= 0 && @nd_block[nid] >= 0
43444344 rt = infer_type(recv)
43454345 if rt == "string" || rt == "mutable_str"