Skip to content

Commit

Permalink
TypeChecker constant resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Jul 2, 2022
1 parent 37943d3 commit 84a6d4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/solargraph/type_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ def method_return_type_problems_for pin
# @param pin [Pin::Base]
# @return [Boolean]
def resolved_constant? pin
api_map.get_constants('', pin.binder.tag).any? { |pin| pin.name == pin.return_type.namespace && ['Class', 'Module'].include?(pin.return_type.name) }
api_map.get_constants('', pin.binder.tag)
.select { |p| p.name == pin.return_type.namespace }
.any? do |p|
inferred = p.infer(api_map)
['Class', 'Module'].include?(inferred.name)
end
end

def virtual_pin? pin
Expand Down
9 changes: 9 additions & 0 deletions spec/type_checker/levels/normal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ def bar; end
expect(checker.problems.first.message).to include('Unresolved')
end

it 'reports unresolved return tags in root namespace' do
checker = type_checker(%(
# @return [UnknownClass]
def bar; end
))
expect(checker.problems).to be_one
expect(checker.problems.first.message).to include('Unresolved')
end

it 'validates existing type tags' do
checker = type_checker(%(
# @type [Integer]
Expand Down

0 comments on commit 84a6d4f

Please sign in to comment.