diff --git a/lib/steep/source.rb b/lib/steep/source.rb index 7cda377d..17fbcbf0 100644 --- a/lib/steep/source.rb +++ b/lib/steep/source.rb @@ -496,6 +496,14 @@ def self.insert_type_node(node, comments) # Skip when :def, :defs # Skip + when :kwargs + # skip + when :pair + key, value = node.children + key = insert_type_node(key, comments.except(last_line)) + value = insert_type_node(value, comments) + node = node.updated(nil, [key, value]) + return adjust_location(node) when :masgn lhs, rhs = node.children node = node.updated(nil, [lhs, insert_type_node(rhs, comments)]) diff --git a/test/source_test.rb b/test/source_test.rb index 6ad5dd2f..7c0f378b 100644 --- a/test/source_test.rb +++ b/test/source_test.rb @@ -779,6 +779,47 @@ def self.baz(x) = 123 #: Numeric end end + def test_assertion__kwargs + with_factory do |factory| + source = Steep::Source.parse(<<~RUBY, path: Pathname("foo.rb"), factory: factory) + foo( + a: "", #: "" + b: [], #: Array[String] + c: "" + ) + RUBY + + _receiver, _name, *args = source.node.children + args[0].tap do |kwargs| + assert_equal :kwargs, kwargs.type + + kwargs.children[0].tap do |pair| + assert_equal :pair, pair.type + key, value = pair.children + + assert_equal :sym, key.type + assert_equal :assertion, value.type + end + + kwargs.children[1].tap do |pair| + assert_equal :pair, pair.type + key, value = pair.children + + assert_equal :sym, key.type + assert_equal :assertion, value.type + end + + kwargs.children[2].tap do |pair| + assert_equal :pair, pair.type + key, value = pair.children + + assert_equal :sym, key.type + assert_equal :str, value.type + end + end + end + end + def test_tapp_send with_factory({ Pathname("foo.rbs") => <<-RBS }) do |factory| class Tapp