Skip to content

Commit 3c5d0d1

Browse files
committed
Kernel.autoload and Kernel.autoload? should use the same caller information
1 parent 5c3b401 commit 3c5d0d1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/main/ruby/truffleruby/core/kernel.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def abort(msg = nil)
203203

204204
def autoload(name, file)
205205
nesting = Primitive.caller_nesting
206-
mod = nesting.first || (Primitive.equal?(Kernel, self) ? Kernel : Object)
206+
mod = nesting.first || Object
207207
if Primitive.equal?(mod, self)
208208
super(name, file) # Avoid recursion
209209
else
@@ -213,10 +213,12 @@ def autoload(name, file)
213213
module_function :autoload
214214

215215
def autoload?(name)
216-
if Primitive.equal?(Kernel, self)
216+
nesting = Primitive.caller_nesting
217+
mod = nesting.first || Object
218+
if Primitive.equal?(mod, self)
217219
super(name) # Avoid recursion
218220
else
219-
Object.autoload?(name)
221+
mod.autoload?(name)
220222
end
221223
end
222224
module_function :autoload?

0 commit comments

Comments
 (0)