Permalink
Browse files

silences "possibly useless use of :: in void context" warnings

The AS utility silence_warnings does not really silence this
one, because it is issued at parse-time. It seemed to in
some places because the constant was the only expression in
the block and therefore it was its return value, that could
potentially be used by silence_warnings are return value of
the yield call.

To bypass the warning we assign to a variable. The chosen
variable is "_" because it is special-cased in parse.c not
to issue an "assigned but unused variable" warning in turn.
  • Loading branch information...
1 parent ef5d857 commit 26c024e95999e545fbef85a25165234af77ea605 @fxn fxn committed Dec 24, 2012
Showing with 3 additions and 7 deletions.
  1. +3 −7 activesupport/test/dependencies_test.rb
@@ -923,10 +923,8 @@ def test_remove_constant_does_not_trigger_loading_autoloads
def test_remove_constant_does_not_autoload_already_removed_parents_as_a_side_effect
with_autoloading_fixtures do
- silence_warnings do
- ::A
- ::A::B
- end
+ _ = ::A # assignment to silence parse-time warning "possibly useless use of :: in void context"
+ _ = ::A::B # assignment to silence parse-time warning "possibly useless use of :: in void context"
ActiveSupport::Dependencies.remove_constant('A')
ActiveSupport::Dependencies.remove_constant('A::B')
assert !defined?(A)
@@ -936,9 +934,7 @@ def test_remove_constant_does_not_autoload_already_removed_parents_as_a_side_eff
def test_load_once_constants_should_not_be_unloaded
with_autoloading_fixtures do
ActiveSupport::Dependencies.autoload_once_paths = ActiveSupport::Dependencies.autoload_paths
- silence_warnings do
- ::A
- end
+ _ = ::A # assignment to silence parse-time warning "possibly useless use of :: in void context"
assert defined?(A)
ActiveSupport::Dependencies.clear
assert defined?(A)

0 comments on commit 26c024e

Please sign in to comment.