Skip to content

Commit c9dfd60

Browse files
authored
Merge pull request #39 from ruby/fix_untyped_function_parameter
Fix for RBS::Types::UntypedFunction
2 parents 053dc89 + 913f756 commit c9dfd60

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
strategy:
3636
fail-fast: false
3737
matrix:
38-
rbs: ['latest', '3.4', '3.2', '3.0', '2.7.0']
38+
rbs: ['latest', '3.6', '3.4', '3.2', '3.0', '2.7.0']
3939
env:
4040
GEMFILE_RBS_VERSION: ${{ matrix.rbs }}
4141
steps:

lib/repl_type_completor/type_analyzer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ def method_call(receiver, method_name, args, kwargs, block, scope, name_match: t
11451145
receiver_vars = receiver.is_a?(Types::InstanceType) ? receiver.params : {}
11461146
free_vars = method.type.free_variables - receiver_vars.keys.to_set
11471147
vars = receiver_vars.merge Types.match_free_variables(free_vars, method_params, given_params)
1148-
if block && method.block
1148+
if block && method.block && method.block.type.respond_to?(:required_positionals)
11491149
params_type = method.block.type.required_positionals.map do |func_param|
11501150
Types.from_rbs_type func_param.type, receiver, vars
11511151
end

lib/repl_type_completor/types.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def self.rbs_methods(type, method_name, args_types, kwargs_type, has_block)
8383
methods_with_score = receivers.flat_map do |receiver_type, klass, singleton|
8484
method = rbs_search_method klass, method_name, singleton
8585
next [] unless method
86-
method.method_types.map do |method_type|
86+
method.method_types.filter_map do |method_type|
87+
next unless method_type.type.respond_to?(:required_positionals)
88+
8789
score = 0
8890
score += 2 if !!method_type.block == has_block
8991
reqs = method_type.type.required_positionals

test/repl_type_completor/test_type_analyze.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def ReplTypeCompletor.handle_exception(e)
1313
end
1414
ReplTypeCompletor::Types.load_rbs_builder unless ReplTypeCompletor::Types.rbs_builder
1515
end
16-
16+
1717
def teardown
1818
ReplTypeCompletor.singleton_class.remove_method(:handle_exception)
1919
ReplTypeCompletor.define_singleton_method(:handle_exception, &@handle_exception_method)
@@ -711,5 +711,13 @@ def test_array_aref
711711
assert_call('[1].[](0).', include: Integer, exclude: [Array, NilClass])
712712
assert_call('[1].[](0){}.', include: Integer, exclude: [Array, NilClass])
713713
end
714+
715+
def test_rbs_untyped_function
716+
# Block of Thread#initialize `(*untyped) { (?) -> void } -> void` is RBS::Types::UntypedFunction
717+
assert_call('Thread.new{_1.', include: NilClass)
718+
assert_call('"a".instance_eval{Thread.new{self.', include: String)
719+
# Proc#call `(?) -> untyped` is RBS::Types::UntypedFunction
720+
assert_call('proc{}.call; 1.', include: Integer)
721+
end
714722
end
715723
end

0 commit comments

Comments
 (0)