Skip to content

Commit

Permalink
Merge pull request #951 from soutaro/nil-error
Browse files Browse the repository at this point in the history
Assign types on method calls in mlhs node
  • Loading branch information
soutaro committed Oct 31, 2023
2 parents 62b0087 + 18d7970 commit cc38703
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/steep/services/completion_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def constant_items_for_context(context, parent: nil, position:, prefix:, items:)
if parent
case parent.type
when :const
const_name = typing.source_index.reference(constant_node: parent)
const_name = typing.source_index.reference(constant_node: parent) or raise "Unknown node in source_index: #{parent}"
consts = context.type_env.constant_env.children(const_name)
end
else
Expand Down
2 changes: 2 additions & 0 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,8 @@ def type_masgn_type(mlhs_node, rhs_type, masgn:, optional:)
_, constr = constr.gvasgn(asgn_node, type)
when :mlhs
constr = (constr.type_masgn_type(asgn_node, type, masgn: masgn, optional: optional) or return)
else
_, constr = constr.synthesize_children(asgn_node).add_typing(asgn_node, type: AST::Builtin.any_type)
end

if node.type == :splat
Expand Down
21 changes: 21 additions & 0 deletions test/completion_provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,27 @@ class World
end
end

def test_on_colon2_call_masgn
with_checker <<EOF do
class Hello
class World
end
end
EOF
CompletionProvider.new(source_text: <<-EOR, path: Pathname("foo.rb"), subtyping: checker).tap do |provider|
Hello::
a, b = []
EOR

provider.run(line: 1, column: 7).tap do |items|
items.grep(CompletionProvider::ConstantItem).tap do |items|
assert_equal [:World], items.map(&:identifier).sort
end
end
end
end
end

def test_simple_method_name_item_two_defs
with_checker <<~RBS do
class TestClass
Expand Down

0 comments on commit cc38703

Please sign in to comment.