Fixed visibility at method definition

There was a problem with visibility state from proc that straddles a fiber or is independent.

Therefore, it has been changed to give priority to env objects, if any.
Also, added "separate module" flag to block traversal to a higher level env object.

Note that the "separate module" flag is now set when calling blocks with the `mrb_yield_with_class()` function.

fixed https://github.com/mruby/mruby/issues/6494
This commit is contained in:
dearblue
2025-04-09 22:20:33 +09:00
parent 52de3b7e10
commit 3fd5e1c250
12 changed files with 169 additions and 34 deletions
+45
View File
@@ -831,6 +831,51 @@ assert('method visibility') do
assert_equal :test, v.test_private { :test }
end
assert('method visibility with meta programming') do
assert_equal "GOOD!" do
f = nil
c = Class.new {
private
f = ->(&blk) {
class_eval(&blk)
}
}
f.call {
def good!
"GOOD!"
end
}
c.new.good!
end
assert_equal "GOOD!" do
c = Class.new
c.class_eval {
private
c.class_eval {
def good!
"GOOD!"
end
}
}
c.new.good!
end
assert_raise NoMethodError do
f = nil
c = Class.new {
private
f = -> {
def bad!
"BAD!"
end
}
}
f.call
c.new.bad!
end
end
assert('Module#module_function') do
module M
def modfunc; end