Actions
Bug #22109
openUnexpected or misleading error when subclass of a ractor calls a new method on itself
Bug #22109:
Unexpected or misleading error when subclass of a ractor calls a new method on itself
Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux]
Description
Hey hey!
When I run the following code:
class SubRactor < Ractor
attr_accessor :foo
end
SubRactor.new { puts foo }.join
I get the following error:
can not access instance variables of shareable objects from non-main Ractors (Ractor::IsolationError)
Unclear if I shouldn't get an error of any sort in this situation, but if this is a legitimate error situation, this error seems inaccurate since Ractors can obviously access instance variables of shareable objects.
A tiny script that shows that:
class C
attr_accessor :foo
def initialize = self.foo = 100
INSTANCE = new.freeze
end
raise "not shareable!" unless Ractor.shareable?(C::INSTANCE)
Ractor.new { puts C::INSTANCE.foo }.join
This prints out 100 as expected instead of giving that error.
This happens on both:
ruby 4.1.0dev (2026-06-11T14:25:18Z master 8e8682fc23) +PRISM [x86_64-linux]
and
ruby 4.0.5 (2026-05-20 revision 64336ffd0e) +PRISM [x86_64-linux]
The script is so puny seems I shouldn't upload the file but let me know if I should just always upload a script file when filing these even when they are trivially small.
Cheers!
Actions