Skip to content

Commit

Permalink
Refine the error message for hidden variables
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Nov 7, 2021
1 parent 334b69e commit ec657f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions test/ruby/test_iseq.rb
Expand Up @@ -135,6 +135,11 @@ def test_ractor_unshareable_outer_variable
assert_raise_with_message(Ractor::IsolationError, /`#{name}'/) do
Ractor.make_shareable(y)
end
obj = Object.new
def obj.foo(*) ->{super} end
assert_raise_with_message(Ractor::IsolationError, /hidden variable/) do
Ractor.make_shareable(obj.foo)
end
end

def test_disasm_encoding
Expand Down
11 changes: 8 additions & 3 deletions vm.c
Expand Up @@ -1035,9 +1035,14 @@ env_copy(const VALUE *src_ep, VALUE read_only_variables)
if (id == src_env->iseq->body->local_table[j]) {
VALUE v = src_env->env[j];
if (!rb_ractor_shareable_p(v)) {
rb_raise(rb_eRactorIsolationError,
"can not make shareable Proc because it can refer unshareable object %"
"+" PRIsVALUE " from variable `%" PRIsVALUE "'", v, rb_id2str(id));
VALUE name = rb_id2str(id);
VALUE msg = rb_sprintf("can not make shareable Proc because it can refer"
" unshareable object %+" PRIsVALUE " from ", v);
if (name)
rb_str_catf(msg, "variable `%" PRIsVALUE "'", name);
else
rb_str_cat_cstr(msg, "a hidden variable");
rb_exc_raise(rb_exc_new_str(rb_eRactorIsolationError, msg));
}
env_body[j] = v;
rb_ary_delete_at(read_only_variables, i);
Expand Down

0 comments on commit ec657f4

Please sign in to comment.