diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-03-27 15:08:52 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-04-10 00:29:05 -0700 |
commit | 900e83b50115afda3f79712310e4cb95e4508972 (patch) | |
tree | 07c581a76af2b2e135f034eb52a9e81401e6e131 /bootstraptest | |
parent | defc0ee9d172c2caa8742cc682a8aa389942d6ef (diff) |
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]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2987
Diffstat (limited to 'bootstraptest')
-rw-r--r-- | bootstraptest/test_eval.rb | 8 | ||||
-rw-r--r-- | bootstraptest/test_insns.rb | 4 | ||||
-rw-r--r-- | bootstraptest/test_syntax.rb | 6 |
3 files changed, 12 insertions, 6 deletions
diff --git a/bootstraptest/test_eval.rb b/bootstraptest/test_eval.rb index fa04323b7f..5d2593c306 100644 --- a/bootstraptest/test_eval.rb +++ b/bootstraptest/test_eval.rb @@ -250,7 +250,9 @@ assert_equal 'ok', %q{ assert_equal 'ok', %q{ begin - 12.instance_eval { @@a } + class A + 12.instance_eval { @@a } + end rescue NameError :ok end @@ -258,7 +260,9 @@ assert_equal 'ok', %q{ assert_equal 'ok', %q{ begin - 12.instance_exec { @@a } + class A + 12.instance_exec { @@a } + end rescue NameError :ok end diff --git a/bootstraptest/test_insns.rb b/bootstraptest/test_insns.rb index 1269d7d013..cb54d0d3f7 100644 --- a/bootstraptest/test_insns.rb +++ b/bootstraptest/test_insns.rb @@ -64,8 +64,8 @@ tests = [ [ 'setinstancevariable', %q{ @x = true }, ], [ 'getinstancevariable', %q{ @x = true; @x }, ], - [ 'setclassvariable', %q{ @@x = true }, ], - [ 'getclassvariable', %q{ @@x = true; @@x }, ], + [ 'setclassvariable', %q{ class A; @@x = true; end }, ], + [ 'getclassvariable', %q{ class A; @@x = true; @@x end }, ], [ 'setconstant', %q{ X = true }, ], [ 'setconstant', %q{ Object::X = true }, ], diff --git a/bootstraptest/test_syntax.rb b/bootstraptest/test_syntax.rb index a111990a1f..fa27bf2aeb 100644 --- a/bootstraptest/test_syntax.rb +++ b/bootstraptest/test_syntax.rb @@ -268,8 +268,10 @@ assert_equal %q{}, %q{ defined?(@@a) } assert_equal %q{class variable}, %q{ - @@a = 1 - defined?(@@a) + class A + @@a = 1 + defined?(@@a) + end } assert_equal %q{}, %q{ defined?($a) |