Bug #13249 ยป warn-scope-visibility-in-method-13249.patch
test/ruby/test_class.rb | ||
---|---|---|
[:module_function, :extend_object, :append_features, :prepend_features])
|
||
end
|
||
def test_visibility_inside_method
|
||
assert_warn(/calling private without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
|
||
Class.new do
|
||
def self.foo
|
||
private
|
||
end
|
||
foo
|
||
end
|
||
end
|
||
assert_warn(/calling protected without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
|
||
Class.new do
|
||
def self.foo
|
||
protected
|
||
end
|
||
foo
|
||
end
|
||
end
|
||
assert_warn(/calling public without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
|
||
Class.new do
|
||
def self.foo
|
||
public
|
||
end
|
||
foo
|
||
end
|
||
end
|
||
end
|
||
def test_method_redefinition
|
||
feature2155 = '[ruby-dev:39400]'
|
||
test/ruby/test_module.rb | ||
---|---|---|
assert_match(/: warning: previous definition of foo/, stderr)
|
||
end
|
||
def test_module_function_inside_method
|
||
assert_warn(/calling module_function without arguments inside a method may not have the intended effect/, '[ruby-core:79751]') do
|
||
Module.new do
|
||
def self.foo
|
||
module_function
|
||
end
|
||
foo
|
||
end
|
||
end
|
||
end
|
||
def test_protected_singleton_method
|
||
klass = Class.new
|
||
x = klass.new
|
vm_method.c | ||
---|---|---|
}
|
||
static void
|
||
vm_cref_set_visibility(rb_method_visibility_t method_visi, int module_func)
|
||
vm_cref_set_visibility(rb_method_visibility_t method_visi, int module_func, int check_method)
|
||
{
|
||
rb_scope_visibility_t *scope_visi = (rb_scope_visibility_t *)&rb_vm_cref()->scope_visi;
|
||
rb_scope_visibility_t *scope_visi;
|
||
if (check_method) {
|
||
/* Check for public/protected/private/module_function called inside a method */
|
||
rb_control_frame_t *cfp = rb_current_execution_context()->cfp+1;
|
||
if (cfp && cfp->iseq && cfp->iseq->body->type == ISEQ_TYPE_METHOD) {
|
||
rb_warn("calling %s without arguments inside a method may not have the intended effect",
|
||
rb_id2name(rb_frame_callee()));
|
||
}
|
||
}
|
||
scope_visi = (rb_scope_visibility_t *)&rb_vm_cref()->scope_visi;
|
||
scope_visi->method_visi = method_visi;
|
||
scope_visi->module_func = module_func;
|
||
}
|
||
... | ... | |
void
|
||
rb_scope_visibility_set(rb_method_visibility_t visi)
|
||
{
|
||
vm_cref_set_visibility(visi, FALSE);
|
||
vm_cref_set_visibility(visi, FALSE, 0);
|
||
}
|
||
static void
|
||
rb_scope_module_func_set(void)
|
||
{
|
||
vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE);
|
||
vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE, 1);
|
||
}
|
||
const rb_cref_t *rb_vm_cref_in_context(VALUE self, VALUE cbase);
|
||
... | ... | |
set_visibility(int argc, const VALUE *argv, VALUE module, rb_method_visibility_t visi)
|
||
{
|
||
if (argc == 0) {
|
||
rb_scope_visibility_set(visi);
|
||
vm_cref_set_visibility(visi, FALSE, 1);
|
||
}
|
||
else {
|
||
set_method_visibility(module, argc, argv, visi);
|