Skip to content

Improve overload resolution and macro handling in Chain::Call - #34

Closed
apiology wants to merge 3 commits into
masterfrom
pin-caching-2-chain-call-refactor
Closed

Improve overload resolution and macro handling in Chain::Call#34
apiology wants to merge 3 commits into
masterfrom
pin-caching-2-chain-call-refactor

Conversation

@apiology

@apiology apiology commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Fixes macro-based return type inference when the macro's $1/$2 placeholders reference the call's actual arguments, not just literal text elsewhere:

class Foo
  # @!macro
  #   @return [$1]
  def self.bar; end
end
Foo.bar(String)
#        ^^^^^^ should substitute into the return type
Before After
Foo.bar(String) inferred type nil String

Root cause: macro/directive reprocessing only ran when normal overload matching produced no type at all. bar's macro-based signature did produce a (wrong) type through the plain matching path, so reprocessing never ran. Chain::Call#inferred_pins's per-overload matching logic is extracted into match_overload_type, restructured so macro reprocessing runs whenever the matched type doesn't actually resolve the macro's placeholders against the real arguments.

Also adds spec coverage for related overload/macro edge cases; 8 of the new specs are pending, linked to tracking issues rather than left silently broken (#1223, #1246).

Testing: bundle exec rspec spec/source/chain/call_spec.rb spec/source_map/clip_spec.rb — 203 examples, 0 failures, 31 pending.

Extract per-overload signature matching in Call#inferred_pins into
match_overload_type, improving how argument/block types are matched
against method overloads and how macro/directive-based pins are
reprocessed when no signature matches by type alone.

Extracted from castwide#1006 (Improve pin caching) as a
standalone piece: this is a type-inference improvement to method call
resolution, independent of the gem pin caching machinery in the rest
of that PR.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
That PR restores the array/tuple literal element-type inference that
master reverted, which is what these pending specs are waiting on.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Filed a new issue after tracing the root cause enough to size a fix:
it's not in Chain::Call's overload matching (this PR's own code) but
in how the resulting local variable's type gets resolved/cached
afterward, a different subsystem than what this PR touches.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@apiology

apiology commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

Resubmitting this against castwide/solargraph upstream.

@apiology apiology closed this Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant