Skip to content

Commit

Permalink
Fix Source.parse crashes with selector-less sendish node
Browse files Browse the repository at this point in the history
`Steep::Source.parse` crashes if the target code contains
selector-less sendish node having annotation comment inside its
block.

Close #1395
  • Loading branch information
tk0miya committed Dec 19, 2024
1 parent fe8a2cd commit d46d141
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/steep/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def self.sendish_node?(node)
receiver_node, name, _, location = deconstruct_send_node!(send_node)

if receiver_node
if location.dot
if location.dot && location.selector
location.selector.line
end
else
Expand Down
15 changes: 15 additions & 0 deletions test/source_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,21 @@ def test: [T] () { (T) -> void } -> T
end
end

def test_selectorless_sendish_node_with_annotation_comment
with_factory({ Pathname("foo.rbs") => <<-RBS }) do |factory|
RBS
source = Steep::Source.parse(<<-EOF, path: Pathname("foo.rb"), factory: factory)
proc{}.() do
x #: nil
end
EOF

source.node.children[0].tap do |node|
assert_equal :send, node.type
end
end
end

def test_find_comment
with_factory() do |factory|
source = Steep::Source.parse(<<~RUBY, path: Pathname("foo.rb"), factory: factory)
Expand Down

0 comments on commit d46d141

Please sign in to comment.