From eec39da3a3f4ea94b8273c2c4aeb99fb28b77545 Mon Sep 17 00:00:00 2001 From: tompng Date: Tue, 22 Oct 2024 02:34:52 +0900 Subject: [PATCH] Fix for RBS::Types::UntypedFunction Fix completion of `Thread.new{here}` --- .github/workflows/test.yml | 2 +- lib/repl_type_completor/type_analyzer.rb | 2 +- test/repl_type_completor/test_type_analyze.rb | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 84a77c0..14bf715 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/lib/repl_type_completor/type_analyzer.rb b/lib/repl_type_completor/type_analyzer.rb index 2d60212..ecb5506 100644 --- a/lib/repl_type_completor/type_analyzer.rb +++ b/lib/repl_type_completor/type_analyzer.rb @@ -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 diff --git a/test/repl_type_completor/test_type_analyze.rb b/test/repl_type_completor/test_type_analyze.rb index 8742603..e5ee662 100644 --- a/test/repl_type_completor/test_type_analyze.rb +++ b/test/repl_type_completor/test_type_analyze.rb @@ -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) @@ -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