From: "ufuk (Ufuk Kayserilioglu)" Date: 2022-03-12T14:09:55+00:00 Subject: [ruby-core:107863] [Ruby master Bug#18624] `const_source_location` returns [false, 0] when autoload is defined for the constant Issue #18624 has been updated by ufuk (Ufuk Kayserilioglu). This is a duplicate of Issue #17354 and @jeremyevans0, in that issue, you had argued that just because the autoload location was known didn't mean that the constant would be guaranteed to be defined by that file. I believe this was also discussed in the Dev Meeting at the time and a consensus wasn't reached: https://bugs.ruby-lang.org/issues/17354#note-12 I suggest we close this issue and continue the conversation on #17354 ---------------------------------------- Bug #18624: `const_source_location` returns [false, 0] when autoload is defined for the constant https://bugs.ruby-lang.org/issues/18624#change-96804 * Author: pocke (Masataka Kuwabara) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0dev (2022-03-11T08:38:13Z master 2e4516be26) [x86_64-linux] * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- `const_source_location` returns `[false, 0]` unexpectedly with the following code. ```ruby # test.rb path = File.join(__dir__, 'test2') Object.autoload 'Test2', path require path p Object.const_source_location 'Test2' ``` ```ruby # test2.rb class Test2 end ``` ```bash $ ruby -v test.rb ruby 3.2.0dev (2022-03-11T08:38:13Z master 2e4516be26) [x86_64-linux] [false, 0] ``` I expect it returns `['/path/to/test2.rb', 2]`, but it doesn't. Ruby 2.7 ~ 3.1 have the same behavior. I actually encountered this problem in a Rails app with Zeitwerk. The following codes are a reproducing example with Zeitwerk. `loader.setup` calls `autoload`, so it causes the same problem. ```ruby # test.rb require "zeitwerk" loader = Zeitwerk::Loader.for_gem loader.setup require File.join(__dir__, 'test2') p Zeitwerk::VERSION p Object.const_source_location 'Test2' ``` ```ruby # test2.rb class Test2 end ``` -- https://bugs.ruby-lang.org/ Unsubscribe: