From caaa36b4e6d0d59f0aa21049c063b140aa5aae4f Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 25 Sep 2020 18:31:04 +0900 Subject: prohibi method call by defined_method in other racotrs We can not call a non-isolated Proc in multiple ractors. --- bootstraptest/test_ractor.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'bootstraptest') diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index ff99521a76..a71f00672b 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -724,6 +724,17 @@ assert_equal 'can not set constants with non-shareable objects by non-main Racto end } +# define_method is not allowed +assert_equal "defined in a different Ractor", %q{ + str = "foo" + define_method(:buggy){|i| str << "#{i}"} + begin + Ractor.new{buggy(10)}.take + rescue => e + e.cause.message + end +} + # Immutable Array and Hash are shareable, so it can be shared with constants assert_equal '[1000, 3]', %q{ A = Array.new(1000).freeze # [nil, ...] -- cgit v1.2.3