Skip to content

Commit

Permalink
Fix InvalidOverloadMethodError on overloading extended method
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke committed Apr 4, 2023
1 parent 0c2c54c commit ccdcb47
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/rbs/definition_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,6 @@ def build_singleton0(type_name)
definition.class_variables.merge!(defn.class_variables)
end

all_interfaces = one_ancestors.each_extended_interface.flat_map do |interface|
other_interfaces = ancestor_builder.interface_ancestors(interface.name).ancestors #: Array[Definition::Ancestor::Instance]
other_interfaces = other_interfaces.select {|ancestor| ancestor.source }
[interface, *other_interfaces]
end
interface_methods = interface_methods(all_interfaces)
import_methods(definition, type_name, methods, interface_methods, Substitution.new)

one_ancestors.each_extended_module do |mod|
mod.args.each do |arg|
validate_type_presence(arg)
Expand All @@ -256,7 +248,12 @@ def build_singleton0(type_name)
define_instance(definition, mod.name, subst)
end

interface_methods = interface_methods(one_ancestors.each_extended_interface.to_a)
all_interfaces = one_ancestors.each_extended_interface.flat_map do |interface|
other_interfaces = ancestor_builder.interface_ancestors(interface.name).ancestors #: Array[Definition::Ancestor::Instance]
other_interfaces = other_interfaces.select {|ancestor| ancestor.source }
[interface, *other_interfaces]
end
interface_methods = interface_methods(all_interfaces)
import_methods(definition, type_name, methods, interface_methods, Substitution.new)

entry.decls.each do |d|
Expand Down
27 changes: 27 additions & 0 deletions test/rbs/definition_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2566,4 +2566,31 @@ def __id__: () -> void
end
end
end

def test_extend_overload
SignatureManager.new do |manager|
manager.files[Pathname("foo.rbs")] = <<~EOF
module M
def f: () -> Integer
end
class A
extend M
def self.f: () -> String | ...
end
EOF

manager.build do |env|
builder = DefinitionBuilder.new(env: env)

builder.build_singleton(type_name("::A")).tap do |definition|
assert_instance_of Definition, definition

definition.methods[:f].tap do |method|
assert_equal [TypeName("::A"), TypeName("::M")], method.defs.map(&:defined_in)
assert_equal [TypeName("::A"), TypeName("::A")], method.defs.map(&:implemented_in)
end
end
end
end
end
end

0 comments on commit ccdcb47

Please sign in to comment.