Resolve type variables of a reopened declaration by position - #477
Merged
Conversation
RBS 4.1 renamed the core's type parameters, e.g. `Array[Elem]` to `Array[E]`, but RBS files in rbs collections (activesupport, the rbs gem's own shims) still reopen them as `Array[Elem]`, which RBS allows. TypeProf looked up type variables only by the names of the first declaration, so using it with such a collection crashed with "unknown type variable: Elem". Let SigTyVarNode fall back to the name at the same position in the module entity, which also makes the shim workaround in 91bd108 unnecessary.
mame
previously requested changes
Sep 9, 2026
mame
left a comment
Member
There was a problem hiding this comment.
Thanks! Just one place I'd like to simplify. If this looks good to you, feel free
to merge it yourself.
Trying the name first got `class Hash[V, K]; def key_of: () -> V` wrong when the reopened declaration swaps the names. Co-authored-by: Yusuke Endoh <mame@ruby-lang.org>
sinsoku
dismissed
mame’s stale review
September 9, 2026 02:57
I've applied the suggestion, so I'm removing the "request-changes" status to proceed with the merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
RBS 4.1 renamed the core's type parameters (
Array[Elem]becameArray[E]), but RBS files in rbs collections still reopen them with the old names: activesupport in gem_rbs_collection hasmodule Enumerable[unchecked out Elem], and so does the rbs gem's own sig/shims/enumerable.rbs. RBS allows this, asvalidate_type_paramscompares the parameters after renaming them.TypeProf keyed type variable substitution by the names of a single declaration, so with such a collection any method lookup through
Enumerablecrashed and the whole file failed to analyze:#468 met the same limitation with TypeProf's own shim and aligned the shim's names with the core (91bd108), which is not an option for third-party RBS.
Changes
SigTyVarNodemaps a name missing from the substitution to the entity's name at the same position in its own declaration. This is done at lookup time instead of renaming the AST, because the entity's names can change when a declaration is removed in the LSP, while the position stays the same. The workaround from #468 is reverted, so the shim exercises the mapping every time the core RBS is loaded.Verification
bin/typeprof libwith anrbs_collection.yamlthat includes the rbs gem completes without errors.unknown type variable: X/T.🤖 Generated with Claude Code