Fix #74474: rename usages of global using aliases#84317
Draft
jcouv wants to merge 2 commits into
Draft
Conversation
added 2 commits
June 27, 2026 20:41
…s not update usages
…ive-type aliases)
Contributor
|
fyi, you'll need to update the syntax persistent index version so that we'll reanalyze all docs to properly reindex this. |
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.
Fixes #74474
Problem
Renaming a
global usingalias only updated the alias declaration, not its usages in other files. This affected both primitive-type aliases (global using MyInteger = int;) and named-type aliases (global using MyHelper = Some.Helper;).Root cause
Two independent defects:
Index gap (primitive-type aliases).
SyntaxTreeIndex.TryAddAliasInfoonly recorded aliases whose RHSIsSimpleName.intis aPredefinedTypeSyntax, soglobal using MyInteger = int;was never indexed.NamedTypeSymbolReferenceFinder.DetermineGlobalAliasesAsyncqueries the index by the target's metadata name (Int32), found nothing, and never searched the file that usesMyInteger.Alias prefilter (all global aliases).
FindReferenceCache.GetAliasInfogatedSemanticModel.GetAliasInfobehind the current file's using directives (GetAliasNameSet). A global-alias usage in a file with no usings was filtered out, leavingReferenceLocation.Aliasnull, so rename dropped the usage.Fix
PredefinedTypeExtensions.GetMetadataName— maps aPredefinedTypeto its metadata name (e.g.Int32), matching the corresponding type symbol'sISymbol.Name.SyntaxTreeIndex_Create.TryAddAliasInfo— index predefined-type alias targets under their metadata name (mirrors the existingusing X = System.Int32handling).FindReferenceCache.GetAliasInfo+AbstractReferenceFinder.CreateReferenceLocation— also consultstate.GlobalAliasesin the prefilter so global-alias usages resolve theirAliaseven in files with no usings.Populating
ReferenceLocation.Aliasmore often is safe for target-type rename: that path only includes an aliased location whenlocation.Alias.Name == referencedSymbol.Name(e.g. renamingHelperstill skipsMyHelper).Tests
4 new
[Theory]/CombinatorialDatarename tests inAliasTests.vb(withWorkItem), covering primitive and named-type global aliases, renamed from both the declaration and a usage.Validation: full Rename suite (2570) and FindReferences suite (3583) pass.
Known limitation (follow-up)
Native-int aliases (
global using MyPtr = nint;) are still not covered: C# parsesnint/nuintasIdentifierNameSyntax(indexed asnint) while FindReferences searches by symbol nameIntPtr. This is consistent with existing precedent (CSharpDeclaredSymbolInfoFactoryService.GetSpecialTypeNamealso omits native ints) and is left as a follow-up.Microsoft Reviewers: Open in CodeFlow