Skip to content

Commit 0d64e7e

Browse files
committed
Handle Ruby 3.1 eval location change
Ref: ruby/ruby#4519 On Ruby 3.1, `Backtrace::Location#absolute_path` returns `nil` if the code was loaded with eval. That same PR made `require_relative` fallback to `Backtrace::Location#path` in such case, so we're doing the same.
1 parent 9562e21 commit 0d64e7e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/bootsnap/load_path_cache/core_ext/kernel_require.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ def require(path)
4747

4848
alias_method(:require_relative_without_bootsnap, :require_relative)
4949
def require_relative(path)
50+
location = caller_locations(1..1).first
5051
realpath = Bootsnap::LoadPathCache.realpath_cache.call(
51-
caller_locations(1..1).first.absolute_path, path
52+
location.absolute_path || location.path, path
5253
)
5354
require(realpath)
5455
end

0 commit comments

Comments
 (0)