Project

General

Profile

Actions

Bug #17722

open

define_method with shareable results in "defined in a different Ractor"

Added by chucke (Tiago Cardoso) 5 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0dev (2021-03-13 master c7e6914b39) [x86_64-linux]
[ruby-core:102849]

Description

Testing against latest master, and expectinng this to already be handled, I nonetheless found a weird case, for which I managed to build a short reproduction.

class A
  define_method :"a=" do |val|
    instance_variable_set(:"@#{v}", val)
  end
  attr_reader :a

  def initialize(opts)
    opts.each do |k, v|
      puts "#{k} = #{v}"
      __send__(:"#{k}=", v)
    end
  end
end

ractors = []

DEFAULTS = { a: 1 }
Ractor.make_shareable(DEFAULTS)

1.times do
  ractors << Ractor.new do
    a = A.new(DEFAULTS)
  end
end
ractors.map(&:take)

This script fails with "defined in a different Ractor (RuntimeError)".

The error comes from the execution of "define_method". I was under the expectation that it would work, given that the passed value is shareable, so it shouldn't make a difference if it was defined in a different ractor.

No data to display

Actions

Also available in: Atom PDF