From e0deadf2f665e6589ac5f1938a15abbd77a06d78 Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Sun, 11 Jan 2026 17:14:56 -0500 Subject: [PATCH 1/3] Use correct field for self type resolution Add a regression test and fix for self type resolution issue found on a future branch --- lib/solargraph/source/chain.rb | 2 +- spec/type_checker/levels/alpha_spec.rb | 29 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 spec/type_checker/levels/alpha_spec.rb diff --git a/lib/solargraph/source/chain.rb b/lib/solargraph/source/chain.rb index f7a03b552..7aa8dede1 100644 --- a/lib/solargraph/source/chain.rb +++ b/lib/solargraph/source/chain.rb @@ -276,7 +276,7 @@ def infer_from_definitions pins, context, api_map, locals 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..118f4cccf --- /dev/null +++ b/spec/type_checker/levels/alpha_spec.rb @@ -0,0 +1,29 @@ +# 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 + end +end From 176b50649e01ccbeb0013bc439093515f3d30760 Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Sun, 11 Jan 2026 18:05:51 -0500 Subject: [PATCH 2/3] Fix another location with another test case --- lib/solargraph/source/chain.rb | 2 +- spec/type_checker/levels/alpha_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/solargraph/source/chain.rb b/lib/solargraph/source/chain.rb index 7aa8dede1..e9722fcc4 100644 --- a/lib/solargraph/source/chain.rb +++ b/lib/solargraph/source/chain.rb @@ -271,7 +271,7 @@ 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 diff --git a/spec/type_checker/levels/alpha_spec.rb b/spec/type_checker/levels/alpha_spec.rb index 118f4cccf..4fd591fda 100644 --- a/spec/type_checker/levels/alpha_spec.rb +++ b/spec/type_checker/levels/alpha_spec.rb @@ -25,5 +25,26 @@ def bing 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 From 45ea8955b5c0c3c95332489cbb93f5529690d9f0 Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Sun, 11 Jan 2026 18:19:34 -0500 Subject: [PATCH 3/3] Drop now-unneeded @sg-ignore --- lib/solargraph/pin/method.rb | 1 - 1 file changed, 1 deletion(-) 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),