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

Account for RBS untyped functions #2631

Merged
merged 2 commits into from
Sep 30, 2024
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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ GEM
rbi (0.2.0)
prism (~> 1.0)
sorbet-runtime (>= 0.5.9204)
rbs (3.5.3)
rbs (3.6.0)
logger
rdoc (6.6.3.1)
psych (>= 4.0.0)
Expand Down
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 (since v3.6.0) 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
Loading
Loading