diff --git a/lib/solargraph/pin/method.rb b/lib/solargraph/pin/method.rb index 86bf1cd09..e6e0f6503 100644 --- a/lib/solargraph/pin/method.rb +++ b/lib/solargraph/pin/method.rb @@ -92,7 +92,6 @@ def combine_with(other, attrs = {}) end new_attrs = { visibility: combine_visibility(other), - # @sg-ignore https://github.com/castwide/solargraph/pull/1050 explicit: explicit? || other.explicit?, block: combine_blocks(other), node: choose_node(other, :node), diff --git a/lib/solargraph/source/chain.rb b/lib/solargraph/source/chain.rb index f7a03b552..e9722fcc4 100644 --- a/lib/solargraph/source/chain.rb +++ b/lib/solargraph/source/chain.rb @@ -271,12 +271,12 @@ def infer_from_definitions pins, context, api_map, locals else ComplexType.new(types) end - if context.nil? || context.return_type.undefined? + if context.nil? || context.context.undefined? # up to downstream to resolve self type return type end - type.self_to_type(context.return_type) + type.self_to_type(context.context) end # @param type [ComplexType] diff --git a/spec/type_checker/levels/alpha_spec.rb b/spec/type_checker/levels/alpha_spec.rb new file mode 100644 index 000000000..4fd591fda --- /dev/null +++ b/spec/type_checker/levels/alpha_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +describe Solargraph::TypeChecker do + context 'when at alpha level' do + def type_checker code + Solargraph::TypeChecker.load_string(code, 'test.rb', :alpha) + end + + it 'resolves self correctly in arguments' do + checker = type_checker(%( + class Foo + # @param other [self] + # + # @return [String] + def bar other + other.bing + end + + # @return [String] + def bing + 'bing' + end + end + )) + + expect(checker.problems.map(&:message)).to eq([]) + end + + it 'resolves self correctly in arguments (second case)' do + checker = type_checker(%( + class Blah + # @return [String] + attr_reader :filename + + # @param filename [String] + def initialize filename + @filename = filename + end + + # @param location [self] + def contain? location + filename == location.filename + end + end + )) + + expect(checker.problems.map(&:message)).to eq([]) + end + end +end