From 4417321d1c0509edbd4fcf55d8a49de9c38e8ec2 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 18 May 2025 18:50:02 +0900 Subject: [PATCH 1/2] Add more test code for method visibility This test corresponds to the first issue of #6494. Complement to #6512. --- test/t/module.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/t/module.rb b/test/t/module.rb index 9645c8667..2827f5e27 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -839,6 +839,16 @@ assert('method visibility with meta programming') do f.call c.new.bad! end + + assert_raise NoMethodError do + c = Class.new { + -> { private }.call + def bad! + "BAD!" + end + } + c.new.bad! + end end assert('Module#module_function') do From 36df8593332c6324be16df2b73d934f8436d3b57 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 18 May 2025 18:52:32 +0900 Subject: [PATCH 2/2] Revert "class.c (find_visibility_scope): when callinfo returns, *ep == NULL; #6512" This reverts commit 3879b95a6223846bc6763d84cb8c0282a6792d31. This is because the code first reported in #6494 no longer works. --- src/class.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class.c b/src/class.c index 814bfbf81..ba413dfb1 100644 --- a/src/class.c +++ b/src/class.c @@ -764,7 +764,7 @@ find_visibility_scope(mrb_state *mrb, const struct RClass *c, int n, mrb_callinf if (check_visibility_break(p, c, ci, NULL)) { mrb_assert(ci->u.env); - *ep = NULL; + *ep = (ci->u.env->tt == MRB_TT_ENV ? ci->u.env : NULL); *cp = ci; return; }