aboutsummaryrefslogtreecommitdiffstats
path: root/vm_method.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-07-31 17:03:11 -0700
committerJeremy Evans <code@jeremyevans.net>2019-08-01 08:52:15 -0700
commitef45a57801a2ae8621b0cde59f11159f89f0a8dc (patch)
tree2b30a7ebea2497b1efc49cfc23d95f4e214a99ea /vm_method.c
parentb8e351a1b9a16ce27f53d15051a1d1f83911b8cb (diff)
downloadruby-ef45a57801a2ae8621b0cde59f11159f89f0a8dc.tar.gz
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.c4
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 {