mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user