Skip to content

Commit

Permalink
Account for RBS untyped functions (#2631)
Browse files Browse the repository at this point in the history
* Upgrade RBS and re-generate gem RBIs

* Account for untyped functions in RBS indexing
  • Loading branch information
vinistock authored Sep 30, 2024
1 parent 88785b7 commit f5f4446
Show file tree
Hide file tree
Showing 6 changed files with 542 additions and 5,192 deletions.
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

0 comments on commit f5f4446

Please sign in to comment.