From 48da3ea13ea4da18f1281f52314d7a2a224ff36b Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Mon, 13 Jun 2022 15:57:14 +0900 Subject: [PATCH] Type check anonymous block forwarding --- lib/steep/type_construction.rb | 14 ++++++++++++-- test/type_construction_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/steep/type_construction.rb b/lib/steep/type_construction.rb index 237b4df9e..fd8fe0982 100644 --- a/lib/steep/type_construction.rb +++ b/lib/steep/type_construction.rb @@ -2299,7 +2299,8 @@ def synthesize(node, hint: nil, condition: false) yield_self do value = node.children[0] - if hint.is_a?(AST::Types::Proc) && value.type == :sym + case + when hint.is_a?(AST::Types::Proc) && value && value.type == :sym if hint.one_arg? # Assumes Symbol#to_proc implementation param_type = hint.type.params.required[0] @@ -2333,9 +2334,18 @@ def synthesize(node, hint: nil, condition: false) else Steep.logger.error "Passing multiple args through Symbol#to_proc is not supported yet" end + when value == nil + type = AST::Types::Proc.new( + type: method_context.method_type.block.type, + location: nil, + block: nil + ) + if method_context.method_type.block.optional? + type = AST::Types::Union.build(types: [type, AST::Builtin.nil_type]) + end end - type ||= synthesize(node.children[0], hint: hint).type + type ||= synthesize(value, hint: hint).type add_typing node, type: type end diff --git a/test/type_construction_test.rb b/test/type_construction_test.rb index 0ea3b3cbf..610a37ce5 100644 --- a/test/type_construction_test.rb +++ b/test/type_construction_test.rb @@ -9121,4 +9121,26 @@ module Mod end end end + + def test_anonymouse_block_forwarding + with_checker(< void } -> void +end +RBS + source = parse_ruby(<