Skip to content

Commit 445c782

Browse files
committed
[prototype runtime] Find redefined methods
1 parent 36e53a2 commit 445c782

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/rbs/prototype/runtime.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def skip_singleton_method?(module_name:, method:, accessibility:)
2727
method_definition = @builder.build_singleton(module_name.absolute!).methods[method.name]
2828
return false unless method_definition
2929

30+
return false unless method_definition.defs.any? do |type_def|
31+
type_def.implemented_in&.relative!.to_s == method.owner.to_s.delete_prefix("#<Class:").delete_suffix(">")
32+
end
33+
3034
method_definition.accessibility == accessibility
3135
end
3236

@@ -36,6 +40,10 @@ def skip_instance_method?(module_name:, method:, accessibility:)
3640
method_definition = @builder.build_instance(module_name.absolute!).methods[method.name]
3741
return false unless method_definition
3842

43+
return false unless method_definition.defs.any? do |type_def|
44+
type_def.implemented_in&.relative!.to_s == method.owner.to_s
45+
end
46+
3947
method_definition.accessibility == accessibility
4048
end
4149

test/rbs/runtime_prototype_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,21 @@ def self.singleton_todo; end
584584

585585
CONST_DEFINED = 1
586586
CONST_TODO = 1
587+
588+
def self.singleton_inherited; end
589+
def public_inherited; end
587590
end
588591

589592
module TodoModule
590593
def public_defined; end
591594
def public_todo; end
592595
end
593596

597+
class InheritedTodoClass < TodoClass
598+
def self.singleton_inherited; end
599+
def public_inherited; end
600+
end
601+
594602
def test_todo
595603
SignatureManager.new do |manager|
596604
manager.files[Pathname("foo.rbs")] = <<~RBS
@@ -605,10 +613,14 @@ def public_defined: () -> void
605613
def self.singleton_defined: () -> void
606614
def accessibility_mismatch: () -> void
607615
CONST_DEFINED: Integer
616+
def self.singleton_inherited: () -> void
617+
def public_inherited: () -> void
608618
end
609619
module TodoModule
610620
def public_defined: () -> void
611621
end
622+
class InheritedTodoClass < TodoClass
623+
end
612624
end
613625
end
614626
RBS
@@ -647,6 +659,19 @@ def public_todo: () -> untyped
647659
end
648660
end
649661
RBS
662+
663+
p = Runtime.new(patterns: ["RBS::RuntimePrototypeTest::InheritedTodoClass"], env: env, merge: false, todo: true)
664+
assert_write p.decls, <<~RBS
665+
module RBS
666+
class RuntimePrototypeTest < ::Test::Unit::TestCase
667+
class InheritedTodoClass < ::RBS::RuntimePrototypeTest::TodoClass
668+
def self.singleton_inherited: () -> untyped
669+
670+
def public_inherited: () -> untyped
671+
end
672+
end
673+
end
674+
RBS
650675
end
651676
end
652677
end

0 commit comments

Comments
 (0)