Skip to content

Commit

Permalink
Attach type assertion to keyword arg
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Dec 16, 2024
1 parent bdb07eb commit 000f0c3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/steep/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
41 changes: 41 additions & 0 deletions test/source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 000f0c3

Please sign in to comment.