CARVIEW |
Select Language
HTTP/2 200
x-amz-id-2: dsWpUw4DwFK+kszJnXy2akfVHOfKqSep1xAznICayGTrqHhxPgwfxoVeNFbxTomBVhezwmscWAw=
x-amz-request-id: DJN7ZBQA1JHWRK9K
last-modified: Fri, 09 May 2025 04:01:45 GMT
etag: "f1c7358a1a357ef7814724990ae87cd5"
x-amz-server-side-encryption: AES256
server: AmazonS3
content-encoding: gzip
via: 1.1 varnish, 1.1 varnish
content-type: text/plain; charset=utf-8
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 20:38:08 GMT
x-served-by: cache-tyo11970-TYO, cache-bom-vanm7210029-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753303088.942316,VS0,VE302
vary: Accept-Encoding
content-length: 896
From: "mame (Yusuke Endoh) via ruby-core"
Date: 2025-05-09T03:52:41+00:00
Subject: [ruby-core:121927] [Ruby Bug#21314] Kernel#autoload requires the wrong file (?)
Issue #21314 has been reported by mame (Yusuke Endoh).
----------------------------------------
Bug #21314: Kernel#autoload requires the wrong file (?)
https://bugs.ruby-lang.org/issues/21314
* Author: mame (Yusuke Endoh)
* Status: Open
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
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.
```ruby
# main.rb
autoload :A, "./a"
autoload :B, "./b"
p A # fires the autoload of A
```
```ruby
# a.rb
p :A1
B # fires the autoload of B
class A
end
```
```ruby
# 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 '': 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.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/