summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Luis Leal Cardoso Junior <andrehjr@gmail.com>2022-04-09 17:18:44 -0300
committerGitHub <noreply@github.com>2022-04-09 17:18:44 -0300
commit4e3fddc490b6579d189916dd92ac065948703c8e (patch)
tree678e0545cdac47f18512e73413ad800725915c45
parent10e03217024a5f0f96188372d00436992ff1edb1 (diff)
parent9f5fdd31da5a7f43c85b463dde0fe83774f7f4c4 (diff)
downloadpry-4e3fddc490b6579d189916dd92ac065948703c8e.tar.gz
Merge pull request #2244 from jcoleman/patch-1
Weird method location shouldn't match unknown location
-rw-r--r--lib/pry/method/weird_method_locator.rb2
-rw-r--r--spec/fixtures/test_task.rb3
-rw-r--r--spec/method_spec.rb38
3 files changed, 42 insertions, 1 deletions
diff --git a/lib/pry/method/weird_method_locator.rb b/lib/pry/method/weird_method_locator.rb
index e4f58c8f..85614aec 100644
--- a/lib/pry/method/weird_method_locator.rb
+++ b/lib/pry/method/weird_method_locator.rb
@@ -158,7 +158,7 @@ class Pry
alias_name = all_methods_for(target_self).find do |v|
location = target_self.method(v).source_location
- expanded_source_location(location) == renamed_method_source_location
+ location && expanded_source_location(location) == renamed_method_source_location
end
alias_name && Pry::Method(target_self.method(alias_name))
diff --git a/spec/fixtures/test_task.rb b/spec/fixtures/test_task.rb
new file mode 100644
index 00000000..dfa86941
--- /dev/null
+++ b/spec/fixtures/test_task.rb
@@ -0,0 +1,3 @@
+task :test_task do
+ binding
+end
diff --git a/spec/method_spec.rb b/spec/method_spec.rb
index 95ac075c..8f06c484 100644
--- a/spec/method_spec.rb
+++ b/spec/method_spec.rb
@@ -208,6 +208,44 @@ describe Pry::Method do
m = Pry::Method.from_binding(o.borscht)
expect(m.source).to eq Pry::Method(o.method(:paella)).source
end
+
+ it 'should not find a wrong method by matching on nil source location' do
+ included_module = Module.new do
+ def self.included(base)
+ base.send :alias_method, "respond_to_without_variables?", "respond_to?"
+ base.send :alias_method, "respond_to?", "respond_to_with_variables?"
+ end
+
+ def respond_to_with_variables?(sym, include_priv=false)
+ respond_to_without_variables?(sym, include_priv)
+ end
+ end
+
+ o = Object.new
+ class << o
+ attr_reader :tasks
+ def task(name, &block)
+ @tasks ||= {}
+ @tasks[name] = block
+ end
+
+ def load
+ path = File.expand_path("../fixtures/test_task.rb", __FILE__)
+ instance_eval File.read(path), path
+ end
+ end
+
+ o.load
+
+ o2 = Object.new
+ o2.singleton_class.send(:include, included_module)
+
+ # Verify preconditions.
+ expect(o2.method(:respond_to_without_variables?).source_location).to be_nil
+
+ b = o2.instance_eval(&o.tasks[:test_task])
+ expect(Pry::Method.from_binding(b).name).to eq "load"
+ end
end
describe 'super' do