CARVIEW |
Select Language
HTTP/2 200
cache-control: max-age=0, private, must-revalidate
content-type: text/html; charset=utf-8
etag: W/"080cc24b91972ad69f8fd15e44d17a38"
nel: {"report_to":"heroku-nel","response_headers":["Via"],"max_age":3600,"success_fraction":0.01,"failure_fraction":0.1}
referrer-policy: strict-origin-when-cross-origin
report-to: {"group":"heroku-nel","endpoints":[{"url":"https://nel.heroku.com/reports?s=n8VjW7RwZBk%2BrUbqW8ZX9tqfH6sTd8xyP575Mmt7Tg4%3D\u0026sid=e11707d5-02a7-43ef-b45e-2cf4d2036f7d\u0026ts=1753254368"}],"max_age":3600}
reporting-endpoints: heroku-nel="https://nel.heroku.com/reports?s=n8VjW7RwZBk%2BrUbqW8ZX9tqfH6sTd8xyP575Mmt7Tg4%3D&sid=e11707d5-02a7-43ef-b45e-2cf4d2036f7d&ts=1753254368"
server: Heroku
set-cookie: _redmine_session=ZE9yLzVmbVpZcURwaEZ4WVNPNjl4NWRFV1JNUTNHL2RoVFRmVkVNRGJTeS9NNTNreWVlQlI2K1h4UjQ5dkx6YXphK3dSc2Q5amZFbk5SOGtQRU95NFZWc29sTkk5ZUcyZ0F1OXhObGlhbmtyNlFCclVVSWhHSXFtSW1SSFNhVjdnV25VeTUvWEVZZWpvalVjMVNsMW53cmJQWEJHa3hlTk1JY2I5WnkyYnI3eDgxY0EvaXMva1RRTVRIOUM0aFpwLS1wMHJjbDlpN0FhcXNuYnJKM21sbDVRPT0%3D--3c777d592b2baaf708ee18bc92a8a1a3ebc9eb64; path=/; secure; httponly; samesite=lax
strict-transport-security: max-age=63072000; includeSubDomains
vary: Accept
via: 2.0 heroku-router
x-content-type-options: nosniff
x-download-options: noopen
x-frame-options: SAMEORIGIN
x-permitted-cross-domain-policies: none
x-request-id: 928a9ac1-2d9d-11f3-68bf-4d1f19362925
x-runtime: 0.083872
x-xss-protection: 1; mode=block
content-length: 30824
date: Wed, 23 Jul 2025 07:06:08 GMT
Bug #21314: Kernel#autoload requires the wrong file (?) - Ruby - Ruby Issue Tracking System
Project
General
Profile
Tags
Custom queries
Actions
Bug #21314
openKernel#autoload requires the wrong file (?)
Added by mame (Yusuke Endoh) 3 months ago.
Description
While discussing #21154 with some people at the dev meeting, I found a weird behavior of Kernel#autoload
that's hard to explain.
I haven't yet looked at it carefully, but I was asked to create a ticket anyway.
# main.rb
autoload :A, "./a"
autoload :B, "./b"
p A # fires the autoload of A
# a.rb
p :A1
B # fires the autoload of B
class A
end
# b.rb
p :B1
class B
p :B2
p A # expected: requires no file (because a.rb is already being require'ed), and raises a NameError
# actual: the autoload of B is fired (not A!), recursively (not no-op!)
p :B3
end
$ ruby main.rb
:A1
:B1
:B2
:B1 # What?
:B2
:A1
:A2
:A3
A
:B3
b.rb:17:in '<class:B>': uninitialized constant B::A (NameError)
By the way, in this case, a.rb and b.rb are considered dependent each other. We need to consider how autoload should behave in this case. If it is the user's responsibility to avoid such a situation, we would like to be able to clearly explain what kind of situation should be avoided.
Updated by mame (Yusuke Endoh) 3 months ago
- Related to Misc #21154: Document or change Module#autoload? added
Actions
Like1
Like0
Powered by Redmine © 2006-2025 Jean-Philippe Lang
Loading...