File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -361,6 +361,22 @@ def test_error_for_module_instance_variable
361361 RUBY
362362 end
363363
364+ def test_error_for_class_variable
365+ assert_ractor ( <<~'RUBY' )
366+ module ModuleWithUnshareableClassVariable
367+ def self.unshareable = @@unshareable
368+ @@unshareable = Hash.new {}.freeze
369+ end
370+ e = Ractor.new do |mod|
371+ ModuleWithUnshareableClassVariable.unshareable
372+ rescue
373+ $!
374+ end.value
375+ assert_kind_of Ractor::IsolationError, e
376+ assert_match(/from Hash default proc/, e.detailed_message)
377+ RUBY
378+ end
379+
364380 def test_error_for_module_constant
365381 assert_ractor ( <<~'RUBY' )
366382 module ModuleWithUnshareableConstant
Original file line number Diff line number Diff line change @@ -1219,10 +1219,13 @@ CVAR_ACCESSOR_SHOULD_BE_MAIN_RACTOR(VALUE klass, ID id)
12191219static void
12201220cvar_read_ractor_check (VALUE klass , ID id , VALUE val )
12211221{
1222- if (UNLIKELY (rb_ractor_isolation_check_active ()) && !rb_ractor_shareable_p (val )) {
1223- rb_ractor_isolation_violation (
1224- "can not read non-shareable class variable %" PRIsVALUE " from non-main Ractors (%" PRIsVALUE ")" ,
1225- rb_id2str (id ), klass );
1222+ if (UNLIKELY (rb_ractor_isolation_check_active ())) {
1223+ VALUE chain = Qnil ;
1224+ if (!rb_ractor_shareable_p_continue (val , & chain )) {
1225+ rb_ractor_isolation_violation_with_chain (chain ,
1226+ "can not read non-shareable class variable %" PRIsVALUE " from non-main Ractors (%" PRIsVALUE ")" ,
1227+ rb_id2str (id ), klass );
1228+ }
12261229 }
12271230}
12281231
You can’t perform that action at this time.
0 commit comments