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; } 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