From 0d64e7e5e493884dc6a23a3ac4632d069172c4a1 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 2 Aug 2021 11:52:35 +0200 Subject: [PATCH] Handle Ruby 3.1 eval location change Ref: https://github.com/ruby/ruby/pull/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. --- lib/bootsnap/load_path_cache/core_ext/kernel_require.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb b/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb index 6050e806..1fa3688e 100644 --- a/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb +++ b/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb @@ -47,8 +47,9 @@ def require(path) alias_method(:require_relative_without_bootsnap, :require_relative) def require_relative(path) + location = caller_locations(1..1).first realpath = Bootsnap::LoadPathCache.realpath_cache.call( - caller_locations(1..1).first.absolute_path, path + location.absolute_path || location.path, path ) require(realpath) end