aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-03-27 15:08:52 -0700
committerJeremy Evans <code@jeremyevans.net>2020-04-10 00:29:05 -0700
commit900e83b50115afda3f79712310e4cb95e4508972 (patch)
tree07c581a76af2b2e135f034eb52a9e81401e6e131 /variable.c
parentdefc0ee9d172c2caa8742cc682a8aa389942d6ef (diff)
downloadruby-900e83b50115afda3f79712310e4cb95e4508972.tar.gz
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]
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/variable.c b/variable.c
index 9ff0326a14..3bcee434da 100644
--- a/variable.c
+++ b/variable.c
@@ -3064,7 +3064,8 @@ cvar_overtaken(VALUE front, VALUE target, ID id)
st_data_t did = (st_data_t)id;
if (RTEST(ruby_verbose) && original_module(front) != original_module(target)) {
- rb_warning("class variable % "PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
+ rb_raise(rb_eRuntimeError,
+ "class variable % "PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
ID2SYM(id), rb_class_name(original_module(front)),
rb_class_name(original_module(target)));
}