From: eregontp@... Date: 2021-08-07T10:53:08+00:00 Subject: [ruby-core:104820] [Ruby master Bug#15790] Strange interaction between autoload and $LOADED_FEATURES Issue #15790 has been updated by Eregon (Benoit Daloze). Maybe we should remove the constant as well if we remove the autoload? I think that would be natural and simpler semantically. Currently there is some really strange semantics around that, which lead to a lot of complexity (e.g., the concept of "undefined constants": https://github.com/ruby/spec/blob/e60485b648924cffa3bc48578000fe667a7b6a9e/core/module/autoload_spec.rb#L444-L475 On a related note, currently when requiring a file fails, the autoload is not removed: https://github.com/ruby/spec/blob/e60485b648924cffa3bc48578000fe667a7b6a9e/core/module/autoload_spec.rb#L408-L442 I think it would be nice if those 2 cases are consistent (i.e., handle any exception from inside autoload the same way). ---------------------------------------- Bug #15790: Strange interaction between autoload and $LOADED_FEATURES https://bugs.ruby-lang.org/issues/15790#change-93162 * Author: fxn (Xavier Noria) * Status: Open * Priority: Normal * ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- If an autoload fails and we remove its associated file from `$LOADED_FEATURES`, the autoload is back: ``` $ cat x.rb Y = 1 # should be X, emulates a typo $ cat test.rb def au Object.autoload?(:X).inspect end x_rb = File.realpath("x.rb") autoload :X, x_rb puts "before failed autoload autoload path is #{au}" X rescue nil puts "after failed autoload autoload path is #{au}" $LOADED_FEATURES.delete(x_rb) puts "after $LOADED_FEATURES deletion autoload path is #{au}" ``` The output is ``` $ ruby -v test.rb ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-darwin18] before failed autoload autoload path is "/Users/fxn/tmp/x.rb" after failed autoload autoload path is nil after $LOADED_FEATURES deletion autoload path is "/Users/fxn/tmp/x.rb" ``` See? Last line would be expected to print a `nil` autoload path. -- 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>