Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InvalidOverloadMethodError on overloading extended method #1294

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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