diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-08-24 17:11:06 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-10-16 12:50:40 -0700 |
commit | 2993b24a1ecc5fa3cc9f140bfd80669c3a3b7b9c (patch) | |
tree | a7a4720d0dd5232fdf1ebd3fcf809ad6d9066eec /vm_method.c | |
parent | db84123600a2112063441dec4411ab5af6c3a78e (diff) | |
download | ruby-2993b24a1ecc5fa3cc9f140bfd80669c3a3b7b9c.tar.gz |
Warn for calling public/protected/private/module_function without arguments inside method
Calling these methods without an argument does not have the
desired effect inside a method.
Fixes [Bug #13249]
Diffstat (limited to 'vm_method.c')
-rw-r--r-- | vm_method.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/vm_method.c b/vm_method.c index 6465798d30..5ee1773fe2 100644 --- a/vm_method.c +++ b/vm_method.c @@ -1127,8 +1127,20 @@ rb_scope_visibility_set(rb_method_visibility_t visi) } static void +scope_visibility_check(void) +{ + /* 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_this_func())); + } +} + +static void rb_scope_module_func_set(void) { + scope_visibility_check(); vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE); } @@ -1663,7 +1675,8 @@ static VALUE set_visibility(int argc, const VALUE *argv, VALUE module, rb_method_visibility_t visi) { if (argc == 0) { - rb_scope_visibility_set(visi); + scope_visibility_check(); + rb_scope_visibility_set(visi); } else { set_method_visibility(module, argc, argv, visi); |