[#122258] [Ruby Misc#21367] Remove link to ruby-doc.org from www.ruby-lang.org/en/documentation/ — "p8 (Petrik de Heus) via ruby-core" <ruby-core@...>
Issue #21367 has been reported by p8 (Petrik de Heus).
11 messages
2025/05/23
[ruby-core:121927] [Ruby Bug#21314] Kernel#autoload requires the wrong file (?)
From:
"mame (Yusuke Endoh) via ruby-core" <ruby-core@...>
Date:
2025-05-09 03:52:41 UTC
List:
ruby-core #121927
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 '<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.
--
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/