Refine the error message for hidden variables

This commit is contained in:
Nobuyoshi Nakada 2021-10-13 16:48:35 +09:00
Родитель 334b69e504
Коммит ec657f44dc
2 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -135,6 +135,11 @@ class TestISeq < Test::Unit::TestCase
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

11
vm.c
Просмотреть файл

@ -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);