Skip to content

Commit

Permalink
Merge pull request #39 from ruby/fix_untyped_function_parameter
Browse files Browse the repository at this point in the history
Fix for RBS::Types::UntypedFunction
  • Loading branch information
ima1zumi authored Oct 25, 2024
2 parents 053dc89 + 913f756 commit c9dfd60
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rbs: ['latest', '3.4', '3.2', '3.0', '2.7.0']
rbs: ['latest', '3.6', '3.4', '3.2', '3.0', '2.7.0']
env:
GEMFILE_RBS_VERSION: ${{ matrix.rbs }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion lib/repl_type_completor/type_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ def method_call(receiver, method_name, args, kwargs, block, scope, name_match: t
receiver_vars = receiver.is_a?(Types::InstanceType) ? receiver.params : {}
free_vars = method.type.free_variables - receiver_vars.keys.to_set
vars = receiver_vars.merge Types.match_free_variables(free_vars, method_params, given_params)
if block && method.block
if block && method.block && method.block.type.respond_to?(:required_positionals)
params_type = method.block.type.required_positionals.map do |func_param|
Types.from_rbs_type func_param.type, receiver, vars
end
Expand Down
4 changes: 3 additions & 1 deletion lib/repl_type_completor/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def self.rbs_methods(type, method_name, args_types, kwargs_type, has_block)
methods_with_score = receivers.flat_map do |receiver_type, klass, singleton|
method = rbs_search_method klass, method_name, singleton
next [] unless method
method.method_types.map do |method_type|
method.method_types.filter_map do |method_type|
next unless method_type.type.respond_to?(:required_positionals)

score = 0
score += 2 if !!method_type.block == has_block
reqs = method_type.type.required_positionals
Expand Down
10 changes: 9 additions & 1 deletion test/repl_type_completor/test_type_analyze.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def ReplTypeCompletor.handle_exception(e)
end
ReplTypeCompletor::Types.load_rbs_builder unless ReplTypeCompletor::Types.rbs_builder
end

def teardown
ReplTypeCompletor.singleton_class.remove_method(:handle_exception)
ReplTypeCompletor.define_singleton_method(:handle_exception, &@handle_exception_method)
Expand Down Expand Up @@ -711,5 +711,13 @@ def test_array_aref
assert_call('[1].[](0).', include: Integer, exclude: [Array, NilClass])
assert_call('[1].[](0){}.', include: Integer, exclude: [Array, NilClass])
end

def test_rbs_untyped_function
# Block of Thread#initialize `(*untyped) { (?) -> void } -> void` is RBS::Types::UntypedFunction
assert_call('Thread.new{_1.', include: NilClass)
assert_call('"a".instance_eval{Thread.new{self.', include: String)
# Proc#call `(?) -> untyped` is RBS::Types::UntypedFunction
assert_call('proc{}.call; 1.', include: Integer)
end
end
end

0 comments on commit c9dfd60

Please sign in to comment.