diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-07-31 17:03:11 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-08-01 08:52:15 -0700 |
commit | ef45a57801a2ae8621b0cde59f11159f89f0a8dc (patch) | |
tree | 2b30a7ebea2497b1efc49cfc23d95f4e214a99ea /vm_method.c | |
parent | b8e351a1b9a16ce27f53d15051a1d1f83911b8cb (diff) |
Make attr* methods define public methods if self in caller is not same as receiver
Previously, attr* methods could be private even if not in the
private section of a class/module block.
This uses the same approach that ruby started using for define_method
in 1fc33199736f316dd71d0c551edbf514528ddde6.
Fixes [Bug #4537]
Diffstat (limited to 'vm_method.c')
-rw-r--r-- | vm_method.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/vm_method.c b/vm_method.c index 35634d275c..da891229f8 100644 --- a/vm_method.c +++ b/vm_method.c @@ -1135,14 +1135,16 @@ rb_scope_module_func_set(void) vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE); } +const rb_cref_t *rb_vm_cref_in_context(VALUE self, VALUE cbase); void rb_attr(VALUE klass, ID id, int read, int write, int ex) { ID attriv; rb_method_visibility_t visi; const rb_execution_context_t *ec = GET_EC(); + const rb_cref_t *cref = rb_vm_cref_in_context(klass, klass); - if (!ex) { + if (!ex || !cref) { visi = METHOD_VISI_PUBLIC; } else { |