From 0aaa6133ed7365e5037ccdac8b59b00fb13aa50e Mon Sep 17 00:00:00 2001 From: Jemma Issroff Date: Wed, 19 Oct 2022 09:30:41 -0400 Subject: [PATCH] Transition frozen string to frozen root shape Co-Authored-By: Aaron Patterson --- shape.c | 8 -------- spec/ruby/optional/capi/shared/rbasic.rb | 2 +- test/ruby/test_string.rb | 12 ++++++++++++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/shape.c b/shape.c index 1b0f1a5dc9..a7a800ca3c 100644 --- a/shape.c +++ b/shape.c @@ -203,14 +203,6 @@ rb_shape_transition_shape_frozen(VALUE obj) rb_shape_t* next_shape; if (shape == rb_shape_get_root_shape()) { - switch (BUILTIN_TYPE(obj)) { - case T_OBJECT: - case T_CLASS: - case T_MODULE: - break; - default: - return; - } next_shape = rb_shape_get_frozen_root_shape(); } else { diff --git a/spec/ruby/optional/capi/shared/rbasic.rb b/spec/ruby/optional/capi/shared/rbasic.rb index 99c2044bd7..95c3137143 100644 --- a/spec/ruby/optional/capi/shared/rbasic.rb +++ b/spec/ruby/optional/capi/shared/rbasic.rb @@ -10,7 +10,7 @@ describe :rbasic, shared: true do obj, _ = @data.call initial = @specs.get_flags(obj) obj.freeze - @specs.get_flags(obj).should == @freeze | initial + (@specs.get_flags(obj) & 0xFFFF).should == (@freeze | initial) & 0xFFFF end it "supports setting the FREEZE flag" do diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index ab14a3c17b..4add7dfe2f 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -887,6 +887,18 @@ CODE end end + class StringWithIVSet < String + def set_iv + @foo = 1 + end + end + + def test_ivar_set_after_frozen_dup + str = StringWithIVSet.new.freeze + str.dup.set_iv + assert_raise(FrozenError) { str.set_iv } + end + def test_each verbose, $VERBOSE = $VERBOSE, nil