Skip to content

Fix #74474: rename usages of global using aliases#84317

Draft
jcouv wants to merge 2 commits into
dotnet:mainfrom
jcouv:fix-issue-74474-rename-global-using-alias
Draft

Fix #74474: rename usages of global using aliases#84317
jcouv wants to merge 2 commits into
dotnet:mainfrom
jcouv:fix-issue-74474-rename-global-using-alias

Conversation

@jcouv

@jcouv jcouv commented Jun 28, 2026

Copy link
Copy Markdown
Member

Fixes #74474

Problem

Renaming a global using alias 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:

  1. Index gap (primitive-type aliases). SyntaxTreeIndex.TryAddAliasInfo only recorded aliases whose RHS IsSimpleName. int is a PredefinedTypeSyntax, so global using MyInteger = int; was never indexed. NamedTypeSymbolReferenceFinder.DetermineGlobalAliasesAsync queries the index by the target's metadata name (Int32), found nothing, and never searched the file that uses MyInteger.

  2. Alias prefilter (all global aliases). FindReferenceCache.GetAliasInfo gated SemanticModel.GetAliasInfo behind the current file's using directives (GetAliasNameSet). A global-alias usage in a file with no usings was filtered out, leaving ReferenceLocation.Alias null, so rename dropped the usage.

Fix

  • PredefinedTypeExtensions.GetMetadataName — maps a PredefinedType to its metadata name (e.g. Int32), matching the corresponding type symbol's ISymbol.Name.
  • SyntaxTreeIndex_Create.TryAddAliasInfo — index predefined-type alias targets under their metadata name (mirrors the existing using X = System.Int32 handling).
  • FindReferenceCache.GetAliasInfo + AbstractReferenceFinder.CreateReferenceLocation — also consult state.GlobalAliases in the prefilter so global-alias usages resolve their Alias even in files with no usings.

Populating ReferenceLocation.Alias more often is safe for target-type rename: that path only includes an aliased location when location.Alias.Name == referencedSymbol.Name (e.g. renaming Helper still skips MyHelper).

Tests

4 new [Theory]/CombinatorialData rename tests in AliasTests.vb (with WorkItem), 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# parses nint/nuint as IdentifierNameSyntax (indexed as nint) while FindReferences searches by symbol name IntPtr. This is consistent with existing precedent (CSharpDeclaredSymbolInfoFactoryService.GetSpecialTypeName also omits native ints) and is left as a follow-up.

Microsoft Reviewers: Open in CodeFlow
@CyrusNajmabadi

Copy link
Copy Markdown
Contributor

fyi, you'll need to update the syntax persistent index version so that we'll reanalyze all docs to properly reindex this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants