[前][次][番号順一覧][スレッド一覧]

ruby-changes:69620

From: Nobuyoshi <ko1@a...>
Date: Sun, 7 Nov 2021 12:40:41 +0900 (JST)
Subject: [ruby-changes:69620] ec657f44dc (master): Refine the error message for hidden variables

https://git.ruby-lang.org/ruby.git/commit/?id=ec657f44dc

From ec657f44dca3b84fde2a0b3b66c4e0e74a4cdce8 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 13 Oct 2021 16:48:35 +0900
Subject: Refine the error message for hidden variables

---
 test/ruby/test_iseq.rb |  5 +++++
 vm.c                   | 11 ++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 19357a774d2..2b3282d5fb8 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -135,6 +135,11 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L135
     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
diff --git a/vm.c b/vm.c
index 8bf4db3c731..307e9ab931c 100644
--- a/vm.c
+++ b/vm.c
@@ -1035,9 +1035,14 @@ env_copy(const VALUE *src_ep, VALUE read_only_variables) https://github.com/ruby/ruby/blob/trunk/vm.c#L1035
                 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);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]