Skip to content

Commit

Permalink
Account for untyped functions in RBS indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Sep 30, 2024
1 parent f9f2395 commit 7fc52b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,23 @@ def signatures(member)

sig { params(overload: RBS::AST::Members::MethodDefinition::Overload).returns(T::Array[Entry::Parameter]) }
def process_overload(overload)
function = T.cast(overload.method_type.type, RBS::Types::Function)
parameters = parse_arguments(function)
function = overload.method_type.type

block = overload.method_type.block
parameters << Entry::BlockParameter.anonymous if block&.required
if function.is_a?(RBS::Types::Function)
parameters = parse_arguments(function)

parameters
block = overload.method_type.block
parameters << Entry::BlockParameter.anonymous if block&.required
return parameters
end

# Untyped functions are a new RBS feature to declare methods that accept any parameters. For our purposes,
# accepting any argument is equivalent to `...`
if defined?(RBS::Types::UntypedFunction) && function.is_a?(RBS::Types::UntypedFunction)
[Entry::ForwardingParameter.new]
else
[]
end
end

sig { params(function: RBS::Types::Function).returns(T::Array[Entry::Parameter]) }
Expand Down
8 changes: 8 additions & 0 deletions lib/ruby_indexer/test/rbs_indexer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ def test_signature_alias
assert_includes(entry.comments, "Returns `true` if any element of `self` meets a given criterion.")
end

def test_indexing_untyped_functions
entries = @index.resolve_method("call", "Method")

parameters = entries.first.signatures.first.parameters
assert_equal(1, parameters.length)
assert_instance_of(Entry::ForwardingParameter, parameters.first)
end

private

def parse_rbs_methods(rbs, method_name)
Expand Down

0 comments on commit 7fc52b8

Please sign in to comment.