Skip to content

Commit

Permalink
Fix for RBS::Types::UntypedFunction
Browse files Browse the repository at this point in the history
Fix completion of `Thread.new{here}`
  • Loading branch information
tompng committed Oct 21, 2024
1 parent 053dc89 commit eec39da
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 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
9 changes: 8 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,12 @@ 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)
end
end
end

0 comments on commit eec39da

Please sign in to comment.