diff options
author | Jeremy Evans <[email protected]> | 2024-09-20 14:57:56 -0700 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2024-09-21 20:00:23 +0200 |
commit | 9f574fa12f0cbe9d7aa4a11a6c7055ed32f02822 (patch) | |
tree | da282c668d0426a805a293e4c5bcf78fc3a4a3ba /test | |
parent | 75ed086348da66e4cfe9488ae9ece5462dd2aef9 (diff) |
Make Complex#{inspect,to_s} work correctly if real part #inspect returns frozen string
Make static f_format function take a non-frozen string to append
to.
This does not result in an additional allocation for #inspect,
but it does result in an additional allocation for #to_s.
Fixes [Bug #20337]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11657
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_complex.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index c0cfb73235..bb131cee91 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -741,6 +741,17 @@ class Complex_Test < Test::Unit::TestCase assert_equal('(1+2i)', c.inspect) end + def test_inspect_to_s_frozen_bug_20337 + assert_separately([], <<~'RUBY') + class Numeric + def inspect = super.freeze + end + c = Complex(Numeric.new, 1) + assert_match(/\A\(#<Numeric:/, c.inspect) + assert_match(/\A#<Numeric:/, c.to_s) + RUBY + end + def test_marshal c = Complex(1,2) |