From 900e83b50115afda3f79712310e4cb95e4508972 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 27 Mar 2020 15:08:52 -0700 Subject: Turn class variable warnings into exceptions This changes the following warnings: * warning: class variable access from toplevel * warning: class variable @foo of D is overtaken by C into RuntimeErrors. Handle defined?(@@foo) at toplevel by returning nil instead of raising an exception (the previous behavior warned before returning nil when defined? was used). Refactor the specs to avoid the warnings even in older versions. The specs were checking for the warnings, but the purpose of the related specs as evidenced from their description is to test for behavior, not for warnings. Fixes [Bug #14541] --- insns.def | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'insns.def') diff --git a/insns.def b/insns.def index aab5cca065..58349b0ccc 100644 --- a/insns.def +++ b/insns.def @@ -236,7 +236,7 @@ getclassvariable /* "class variable access from toplevel" warning can be hooked. */ // attr bool leaf = false; /* has rb_warning() */ { - val = rb_cvar_get(vm_get_cvar_base(vm_get_cref(GET_EP()), GET_CFP()), id); + val = rb_cvar_get(vm_get_cvar_base(vm_get_cref(GET_EP()), GET_CFP(), 1), id); } /* Set value of class variable id of klass as val. */ @@ -249,7 +249,7 @@ setclassvariable // attr bool leaf = false; /* has rb_warning() */ { vm_ensure_not_refinement_module(GET_SELF()); - rb_cvar_set(vm_get_cvar_base(vm_get_cref(GET_EP()), GET_CFP()), id, val); + rb_cvar_set(vm_get_cvar_base(vm_get_cref(GET_EP()), GET_CFP(), 1), id, val); } /* Get constant variable id. If klass is Qnil and allow_nil is Qtrue, constants -- cgit v1.2.3