Issue #10661 has been updated by Myron Marston.


I'm also seeing this warning from rubygems in the ruby-head builds on travis:

```
/home/travis/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/compatibility.rb:25: warning: possible reference to past scope - path
/home/travis/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:2480: warning: possible reference to past scope - name
/home/travis/.rvm/rubies/ruby-head/lib/ruby/site_ruby/2.3.0/rubygems/specification.rb:2482: warning: possible reference to past scope - name
```

(from https://travis-ci.org/rspec/rspec-support/jobs/45403196)

This shows that it's not just a problem in spec-style suites -- it shows up in normal code that ships with Ruby.  In general, when parts of the stdlib emit warnings, it hinders *everyone's* ability to run Ruby with warnings enabled, as stdlib warnings get mixed in with your own, so you train yourself to ignore warning output since it is always present (or, more likely, you turn warnings off).  IMO, Ruby should not ship with new types of warnings until the stdlib has been updated to avoid the new warning.  Besides ensuring the code ruby ships with is warning-free, it also works as a good vetting tool to show that the situations that the new warning warns about are actually worth having warnings.  In this case, it looks like the warning was committed on release day, with no chance for the community to provide feedback on the warning in a preview or release candidate.

----------------------------------------
Bug #10661: The "possible reference to past scope" warning is quite frustrating and is forcing me to change my variable names from what I want
https://bugs.ruby-lang.org/issues/10661#change-50696

* Author: Myron Marston
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin12.0]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
I find the change in r48986 to be quite frustrating.  It's forcing me to change many of my variable and/or method names if I want to keep my ruby code warning free (which is a thing we enforce in the RSpec code base).

The problem I see is that, in my experience, it's quite common to use the same name for a local variable in one part of a file that you later use for an arg-less method name at a later part in the file.

Consider this ruby command:

~~~
ruby -w -e '[1, 2, 3].sample.tap { |rand| puts "Random value: #{rand}" }; puts "Another random value: #{rand}"'
~~~

This produces:

~~~
-e:1: warning: possible reference to past scope - rand
Random value: 1
Another random value: 0.7483347748677992
~~~

Changing the `rand` call to `self.rand` is one solution I would consider to avoid the warning, but it doesn't work here because `rand` is `private` (as it comes from `Kernel`), so I'm forced to change the block local variable name to a name I do not want.

In RSpec it's an even bigger issue as it's quite common to have a common name for a certain collaborator role in your tests where in some cases there's a helper method (often defined using `let`) that exposes an object for that role and in other tests you might build it in-line and assign it to a local.  In our rspec-mocks test suite, we had 280 warnings from this.  I went through and changed many variable and method names to names I do not like as much (e.g. `the_dbl` instead of `dbl` or `klazz` instead of `klass`) simply to avoid this warning:

https://github.com/rspec/rspec-mocks/commit/3b909ed1a951bbca340ea98c27ab65da7f43881c

While I can understand the kinds of errors this warnings helps you avoid, I think that it is too strict and noisy in its current form.




-- 
https://bugs.ruby-lang.org/