Commit 782b19cc

782b19ccd068Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified

Description

fix: restrict hoisted strlen to matching receiver

Previously compile_string_method_expr returned @hoisted_strlen_var for any str.length call when a hoist was active, even for a different string. This was incorrect — it would return one string's length for another.

Now only reuse the hoisted variable when the receiver's compiled expression matches @hoisted_strlen_recv.

No performance change (this was a latent correctness bug that hadn't triggered in tests). 75/75 pass, bootstrap stable.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
782b19ccd068
Parent
85036c4ce95d

spinel_codegen.rbmodifiedView file

@@ -12588,7 +12588,9 @@
1258812588 def compile_string_method_expr(nid, mname, rc)
1258912589 @needs_string_helpers = 1
1259012590 if mname == "length"
12591- if @hoisted_strlen_var != ""
12591+ # Only use hoisted length if the receiver matches (otherwise we'd
12592+ # return the wrong string's length).
12593+ if @hoisted_strlen_var != "" && @hoisted_strlen_recv == rc
1259212594 return @hoisted_strlen_var
1259312595 end
1259412596 return "(mrb_int)strlen(" + rc + ")"