From ff414c59e3dd1f7cddf6dbb1612f8595df5f6acd Mon Sep 17 00:00:00 2001 From: Ulysse Buonomo Date: Mon, 10 May 2021 14:05:13 +0200 Subject: [PATCH] Ensure we always use `Kernel.caller_locations` [Some popular gem][1] redefine `caller_locations`, hence if used in that context, dead_end would throw an error. Reproduction: ```ruby require "sinatra/base" require "dead_end" class App < Sinatra::Base require_relative "some" end ``` [1]: https://github.com/sinatra/sinatra/blob/5513eb3c7969dc3d15b3c704df63a3ccce9ac9cb/lib/sinatra/base.rb#L1553 --- CHANGELOG.md | 2 ++ lib/dead_end/auto.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5968c0..5e1fa14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## HEAD (unreleased) +- Fix sinatra support for `require_relative` (https://github.com/zombocom/dead_end/pull/63) + ## 1.1.6 - Consider if syntax error caused an unexpected variable instead of end (https://github.com/zombocom/dead_end/pull/58) diff --git a/lib/dead_end/auto.rb b/lib/dead_end/auto.rb index 3e5dbd3..67e23ac 100644 --- a/lib/dead_end/auto.rb +++ b/lib/dead_end/auto.rb @@ -27,7 +27,7 @@ def require_relative(file) if Pathname.new(file).absolute? dead_end_original_require file else - dead_end_original_require File.expand_path("../#{file}", caller_locations(1, 1)[0].absolute_path) + dead_end_original_require File.expand_path("../#{file}", Kernel.caller_locations(1, 1)[0].absolute_path) end rescue SyntaxError => e DeadEnd.handle_error(e)