File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -310,6 +310,22 @@ def test_error_for_module_instance_variable
310310 RUBY
311311 end
312312
313+ def test_error_for_class_variable
314+ assert_ractor ( <<~'RUBY' )
315+ module ModuleWithUnshareableClassVariable
316+ def self.unshareable = @@unshareable
317+ @@unshareable = Hash.new {}.freeze
318+ end
319+ e = Ractor.new do |mod|
320+ ModuleWithUnshareableClassVariable.unshareable
321+ rescue
322+ $!
323+ end.value
324+ assert_kind_of Ractor::IsolationError, e
325+ assert_match(/from Hash default proc/, e.detailed_message)
326+ RUBY
327+ end
328+
313329 def test_error_for_module_constant
314330 assert_ractor ( <<~'RUBY' )
315331 module ModuleWithUnshareableConstant
Original file line number Diff line number Diff line change @@ -1206,10 +1206,13 @@ CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(VALUE klass, ID id)
12061206static void
12071207cvar_read_ractor_check (VALUE klass , ID id , VALUE val )
12081208{
1209- if (UNLIKELY (!rb_ractor_main_p ()) && !rb_ractor_shareable_p (val )) {
1210- rb_raise (rb_eRactorIsolationError ,
1211- "can not read non-shareable class variable %" PRIsVALUE " from non-main Ractors (%" PRIsVALUE ")" ,
1212- rb_id2str (id ), klass );
1209+ if (UNLIKELY (!rb_ractor_main_p ())) {
1210+ VALUE chain = Qnil ;
1211+ if (!rb_ractor_shareable_p_continue (val , & chain )) {
1212+ rb_raise (rb_eRactorIsolationError ,
1213+ "can not read non-shareable class variable %" PRIsVALUE " from non-main Ractors (%" PRIsVALUE ")%" PRIsVALUE ,
1214+ rb_id2str (id ), klass , chain );
1215+ }
12131216 }
12141217}
12151218
You can’t perform that action at this time.
0 commit comments