Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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