Skip to content

Commit

Permalink
silences "possibly useless use of :: in void context" warnings
Browse files Browse the repository at this point in the history
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
fxn committed Dec 24, 2012
1 parent ef5d857 commit 26c024e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions activesupport/test/dependencies_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 def test_remove_constant_does_not_autoload_already_removed_parents_as_a_side_effect
with_autoloading_fixtures do with_autoloading_fixtures do
silence_warnings do _ = ::A # assignment to silence parse-time warning "possibly useless use of :: in void context"
::A _ = ::A::B # assignment to silence parse-time warning "possibly useless use of :: in void context"
::A::B
end
ActiveSupport::Dependencies.remove_constant('A') ActiveSupport::Dependencies.remove_constant('A')
ActiveSupport::Dependencies.remove_constant('A::B') ActiveSupport::Dependencies.remove_constant('A::B')
assert !defined?(A) assert !defined?(A)
Expand All @@ -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 def test_load_once_constants_should_not_be_unloaded
with_autoloading_fixtures do with_autoloading_fixtures do
ActiveSupport::Dependencies.autoload_once_paths = ActiveSupport::Dependencies.autoload_paths ActiveSupport::Dependencies.autoload_once_paths = ActiveSupport::Dependencies.autoload_paths
silence_warnings do _ = ::A # assignment to silence parse-time warning "possibly useless use of :: in void context"
::A
end
assert defined?(A) assert defined?(A)
ActiveSupport::Dependencies.clear ActiveSupport::Dependencies.clear
assert defined?(A) assert defined?(A)
Expand Down

0 comments on commit 26c024e

Please sign in to comment.