Skip to content

Prefer generic superclass reference in get_superclass - #73

Open
apiology wants to merge 1 commit into
fix-gempins-combine-namespace-genericsfrom
fix-reference-superclass-generic-values
Open

Prefer generic superclass reference in get_superclass#73
apiology wants to merge 1 commit into
fix-gempins-combine-namespace-genericsfrom
fix-reference-superclass-generic-values

Conversation

@apiology

@apiology apiology commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Problem: get_superclass takes .first on a class's superclass reference pins, with no preference for one that actually carries generic args over one that doesn't.

A class documented in both YARD (plain Ruby source, generic args unparseable) and RBS (class Sub[T] < Base[T]) gets two separate Reference::Superclass pins for the same fqns - GemPins.combine merges Method/Namespace pins, but not references. Whichever pin was indexed first wins, which is often the YARD one:

store.get_superclass('ActiveSupport::HashWithIndifferentAccess').generic_values
# => [] (the RBS pin's ["T", "U"] never gets picked)

Solution: Prefer a pin with non-empty generic_values when one exists among the candidates, falling back to .first otherwise.

Base branch is #71 (fix-gempins-combine-namespace-generics), not master - this fix depends on that one's Namespace merge to have a non-empty-generics RBS pin to prefer in the first place. It also doesn't fully resolve tl:pr-1329-follow-on in plate-spinner on its own; a further gap remains in substituting a receiver's own generic args into an ancestor's type parameters, not yet root-caused.

This PR was written by Claude Code on behalf of @apiology.

@apiology
apiology force-pushed the fix-reference-superclass-generic-values branch from db212e4 to 9d9d12e Compare September 7, 2026 00:20
@apiology
apiology marked this pull request as ready for review September 7, 2026 02:05
A class documented in both YARD (plain Ruby source, generic args
unparseable) and RBS (e.g. `class Sub[T] < Base[T]`) gets two
Reference::Superclass pins for the same fqns, since GemPins.combine
only merges Method/Namespace pins, not references. get_superclass
took .first, which is whichever pin was indexed first - often the
YARD one, with generic_values always empty.

Prefer a pin that actually carries generic_values when one exists.

Also guards the Hash#[] lookup against nil: superclass_references
is built with a default-proc Hash.new { |h, k| h[k] = [] }, so it
never returns nil at runtime, but RBS's static Hash#[] signature
doesn't reflect that, and Solargraph's own self-typecheck flagged
the resulting Array<Pin::Reference::Superclass>, nil as a real gap
on this line.
@apiology
apiology force-pushed the fix-reference-superclass-generic-values branch from 9d9d12e to 4afc160 Compare September 7, 2026 02:05
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