Project

General

Profile

Actions

Bug #20188

closed

`Module#const_source_location` returns wrong information when real constant was defined but autoload is still ongoing

Added by byroot (Jean Boussier) 4 months ago. Updated 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
[ruby-core:116223]

Description

Ref: https://github.com/fxn/zeitwerk/issues/281

const_source_location keeps returning the location of the autoload call, even after the real constant was defined. It only starts returning the real constant location once the autoload was fully completed.

# /tmp/autoload.rb
File.write("/tmp/const.rb", <<~RUBY)
module Const
  LOCATION = Object.const_source_location(:Const)
end
RUBY

autoload :Const, "/tmp/const"

p Const::LOCATION

Expected Output:

["/tmp/const.rb", 1]

Actual Output:

["/tmp/autoload.rb", 8]

Potential patch: https://github.com/ruby/ruby/pull/9549

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0