From 71de020cbf092ff92be5dcd29ea38b0c9d49edae Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Sat, 30 Apr 2022 21:46:14 +0900 Subject: [PATCH] Remove `to_a` error message The error message is printed because `Factory#interface` is called with unsupported types. This commit adds a guard. --- lib/steep/type_construction.rb | 5 +++++ test/type_construction_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/steep/type_construction.rb b/lib/steep/type_construction.rb index 7d5765c65..2c221d4c0 100644 --- a/lib/steep/type_construction.rb +++ b/lib/steep/type_construction.rb @@ -3981,6 +3981,11 @@ def try_tuple_type(node, hint) end def try_convert(type, method) + case type + when AST::Types::Any, AST::Types::Bot, AST::Types::Top, AST::Types::Var + return + end + interface = checker.factory.interface(type, private: false) if entry = interface.methods[method] method_type = entry.method_types.find do |method_type| diff --git a/test/type_construction_test.rb b/test/type_construction_test.rb index a8bdc5f5c..36b2c9cd1 100644 --- a/test/type_construction_test.rb +++ b/test/type_construction_test.rb @@ -8673,6 +8673,32 @@ def to_a: () -> Array[T] end end + def test_to_a_untyped + with_checker(<<-RBS) do |checker| + RBS + + source = parse_ruby(<<-'RUBY') +# @type var a: untyped +a = _ = nil +[*a] + +# @type var b: top +b = _ = nil +[*b] + +# @type var c: bot +c = _ = nil +[*c] + RUBY + + with_standard_construction(checker, source) do |construction, typing| + _, constr = construction.synthesize(source.node) + + assert_no_error typing + end + end + end + def test_case_const_unexpected_error with_checker(<<-RBS) do |checker| class UnexpectedErrorTest