@@ -637,6 +637,77 @@ def test_warn_frozen_error_warns_on_instance_variable_writes
637637 RUBY
638638 end
639639
640+ def test_warn_frozen_error_marks_shareable_proc_without_freezing
641+ assert_ractor ( <<~'RUBY' )
642+ old = Ractor.warn_frozen_error
643+ begin
644+ Ractor.warn_frozen_error = true
645+ pr = Ractor.shareable_proc { :ok }
646+
647+ assert_equal false, Ractor.shareable?(pr)
648+ assert_equal false, pr.frozen?
649+ assert_equal :ok, pr.call
650+
651+ assert_warning(/would raise FrozenError.*Proc/) do
652+ pr.instance_variable_set(:@mutated, true)
653+ end
654+ assert_equal true, pr.instance_variable_get(:@mutated)
655+ ensure
656+ Ractor.warn_frozen_error = old
657+ end
658+ RUBY
659+ end
660+
661+ def test_warn_frozen_error_marks_shareable_lambda_without_freezing
662+ assert_ractor ( <<~'RUBY' )
663+ old = Ractor.warn_frozen_error
664+ begin
665+ Ractor.warn_frozen_error = true
666+ pr = Ractor.shareable_lambda { :ok }
667+
668+ assert_equal false, Ractor.shareable?(pr)
669+ assert_equal false, pr.frozen?
670+ assert_equal true, pr.lambda?
671+ assert_equal :ok, pr.call
672+
673+ assert_warning(/would raise FrozenError.*Proc/) do
674+ pr.instance_variable_set(:@mutated, true)
675+ end
676+ assert_equal true, pr.instance_variable_get(:@mutated)
677+ ensure
678+ Ractor.warn_frozen_error = old
679+ end
680+ RUBY
681+ end
682+
683+ def test_warn_frozen_error_marks_shareable_proc_self_without_freezing
684+ assert_ractor ( <<~'RUBY' )
685+ old = Ractor.warn_frozen_error
686+ begin
687+ Ractor.warn_frozen_error = true
688+ replacement_self = Object.new
689+ nested = []
690+ replacement_self.instance_variable_set(:@nested, nested)
691+ pr = Ractor.shareable_proc(self: replacement_self) { self }
692+
693+ assert_same replacement_self, pr.call
694+ assert_equal false, replacement_self.frozen?
695+ assert_equal false, nested.frozen?
696+
697+ assert_warning(/would raise FrozenError.*Object/) do
698+ replacement_self.instance_variable_set(:@mutated, true)
699+ end
700+ assert_equal true, replacement_self.instance_variable_get(:@mutated)
701+ assert_warning(/would raise FrozenError.*Array/) do
702+ nested << :mutated
703+ end
704+ assert_equal [:mutated], nested
705+ ensure
706+ Ractor.warn_frozen_error = old
707+ end
708+ RUBY
709+ end
710+
640711 def test_warn_frozen_error_off_uses_normal_make_shareable_freezing
641712 assert_ractor ( <<~'RUBY' )
642713 old = Ractor.warn_frozen_error
@@ -646,6 +717,10 @@ def test_warn_frozen_error_off_uses_normal_make_shareable_freezing
646717 Ractor.make_shareable(ary)
647718 assert_equal true, ary.frozen?
648719 assert_raise(FrozenError) { ary << :mutated }
720+
721+ pr = Ractor.shareable_proc { :ok }
722+ assert_equal true, pr.frozen?
723+ assert_raise(FrozenError) { pr.instance_variable_set(:@mutated, true) }
649724 ensure
650725 Ractor.warn_frozen_error = old
651726 end
0 commit comments