Commit 07c9db07
07c9db0750fbMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · +1 added
Description
Add regression test for String#replace/prepend/insert/clear on locals
These four methods already mutate a string held in a local variable:
the analyzer widens such a local to a mutable_str when it is the
receiver of replace/prepend/insert/concat/<< (the #740/#741
promotion), and clear reassigns the local to "". So s = "abc"; s.replace("xyz") and the prepend/insert/clear forms all match CRuby
rather than being no-ops, as does the String.new receiver path.
The gap reported in the issue (no dispatch through sp_String_replace) is closed; lock the behaviour in with a test covering literal-local and String.new receivers plus negative-index insert.
Closes #1082
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 07c9db0750fb
- Parent
- ddc868e21a25
test/string_replace_prepend_insert_clear.rbaddedView file
# String#replace / prepend / insert / clear mutate a string held in a# local variable. The analyzer widens such a local to a mutable_str# (or, for clear, reassigns it), so these match CRuby instead of being# no-ops. Both string-literal locals and String.new receivers work.s = "abc"s.replace("xyz")p ss2 = "world"s2.prepend("hello ")p s2s3 = "hlo"s3.insert(1, "el")p s3s4 = "hello"s4.clearp s4.length# String.new receivers mutate through the same paths.m = String.new("abc")m.replace("xyz")m.prepend("> ")p mm2 = String.new("hello")m2.clearp m2.length# insert with a negative index counts from the end.s5 = "abcd"s5.insert(-2, "X")p s5