Skip to content

Commit

Permalink
loc.selector may be undefined
Browse files Browse the repository at this point in the history
For `+=` operator.
  • Loading branch information
soutaro committed Apr 24, 2023
1 parent bb739ed commit 88023ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/steep/diagnostic/lsp_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def format(diagnostic)
severity = severity_for(diagnostic)

if severity
range = diagnostic.location&.as_lsp_range or raise
range = diagnostic.location&.as_lsp_range or raise "#{diagnostic.class} object (#{diagnostic.full_message}) instance must have `#location`"

LSP::Interface::Diagnostic.new(
message: diagnostic.full_message,
Expand Down
9 changes: 5 additions & 4 deletions lib/steep/diagnostic/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,14 @@ class NoMethod < Base
def initialize(node:, type:, method:)
loc = case node.type
when :send
node.loc.selector
loc = _ = nil
loc ||= node.loc.operator if node.loc.respond_to?(:operator)
loc ||= node.loc.selector if node.loc.respond_to?(:selector)
loc
when :block
node.children[0].loc.selector
else
node.loc.expression
end
super(node: node, location: loc)
super(node: node, location: loc || node.loc.expression)
@type = type
@method = method
end
Expand Down
20 changes: 20 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10449,4 +10449,24 @@ def test_orasgn_andasgn__global
end
end
end

def test_opasgn_error_report
with_checker(<<~RBS) do |checker|
RBS
source = parse_ruby(<<~RUBY)
x = [1].first
x += 1
RUBY

with_standard_construction(checker, source) do |construction, typing|
type, _, context = construction.synthesize(source.node)

assert_all!(typing.errors) do |error|
assert_operator error, :is_a?, Diagnostic::Ruby::NoMethod
assert_instance_of Parser::Source::Range, error.location
end
end
end
end
end

0 comments on commit 88023ab

Please sign in to comment.