Issue #11547 has been updated by Shugo Maeda.


Scott Bronson wrote:
> Corin, I completely agree.  Recently, Rails's nondeterministic autoload made it very hard for me to discover this problem.  Without the insightful warning, I would have been sunk.
> 
> Shugo Maeda wrote:
> > Instead of changing the behavior of constant lookup, we may be able to introduce a variant of `const_missing` which is invoked when a constant is not directly defined in the target class.
> 
> Couldn't Ruby 3.0 just raise an error instead?  Shugo, your example seems to demonstrate that Ruby is smart enough to realize when the behavior is intentional vs. when it's probably an accident.
> 
> I'd be happy to bang together a patch if the concept seems sound.

The behavior change might be acceptable in Ruby 3.0 if Matz wants.
Experiments with real world applications such as Rails might help his decision.



----------------------------------------
Feature #11547: remove top-level constant lookup
https://bugs.ruby-lang.org/issues/11547#change-57276

* Author: Corin Langosch
* Status: Feedback
* Priority: Normal
* Assignee: 
----------------------------------------
If ruby cannot find a class in the specified scope it uses the top-level constant of the same name if it exists and emits a warning:

~~~
irb(main):006:0> class Auth; end
=> nil
irb(main):007:0> class Twitter; end
=> nil
irb(main):008:0> Twitter::Auth
(irb):8: warning: toplevel constant Auth referenced by Twitter::Auth
=> Auth
~~~

In some cases this is not playing nicely with rails autoloading as can be seen here: https://github.com/rails/rails/issues/6931. Many more issues like this exist.

Imo I don't see any reason why this fallback makes any sense. So I'd like to suggest to remove it completely or at least add an option to disable it.





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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>