You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix NRE in using code fix when qualifying alias-any-type usings - #4381
Found by the fuzz harness (tools/StyleCop.Analyzers.Fuzz, mutate over the extracted-literal corpus, random seed 2026).
Bug: the SA1200 code fix (UsingCodeFixProvider) throws a NullReferenceException in QualifyUsingDirective when it moves a C# 12 alias-any-type using (e.g. using Point = (int X, int Y);, using Numbers = int[];) and has to qualify it. For these aliases, UsingDirectiveSyntax.Name is null.
Fix: when Name is null, qualify each outermost NameSyntax inside the alias target type (NamespaceOrType()). The existing symbol-qualification logic is extracted into QualifyName and reused unchanged.
Test:SA1200OutsideNamespaceCSharp12UnitTests.TestAliasAnyTypeInNamespaceIsMovedAndQualifiedAsync. It failed with the NRE before the fix.
Analyzer cost: none. This is code-fix only.
Known limitations
A named alias declared outside the namespace whose target uses an extern alias in a type argument (e.g. extern alias ext; using Box = global::G<ext::Lib.C>; with using Items = Box[]; inside the namespace) is qualified as G<Lib.C>[], losing the ext:: qualifier.
An alias declared in another file through an extern alias (e.g. extern alias ext; global using Rows = ext::Lib.C[];) is expanded to global::Lib.C[][] when using Items = Rows[]; is moved, also losing the ext:: qualifier.
Both only matter when the referenced library is reachable solely through the extern alias.
❌ Patch coverage is 95.15789% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.63%. Comparing base (b0ba8d8) to head (6e2de21).
The cross-tree fallback drops nullable-reference annotations because FullyQualifiedFormat omits those modifiers. With annotations enabled, global using Row = N.C?[]; in another file and a namespace-local using Matrix = Row[]; produce N.C[][] instead of N.C?[][], changing element nullability. Use a nullable-aware display format compatible with the supported Roslyn baseline and add a multi-file regression test.
This expected output moves TestClass?[] before #nullable enable, outside the annotation context that covered the original alias. When the project's default annotation context is disabled, the fix introduces CS8632 and can break builds that treat warnings as errors. Preserve the alias's nullable context during relocation and make this regression check compiler warnings as well as the fixed text.
… targets
A using alias qualifier (NS::C) is not visible from another alias target in the same
using block, so only extern aliases are preserved. Type arguments are now preserved on
every generic segment, e.g. Outer<ext::C>.Inner<int>.
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
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.
Found by the fuzz harness (
tools/StyleCop.Analyzers.Fuzz,mutateover the extracted-literal corpus, random seed 2026).Bug: the SA1200 code fix (UsingCodeFixProvider) throws a
NullReferenceExceptioninQualifyUsingDirectivewhen it moves a C# 12 alias-any-type using (e.g.using Point = (int X, int Y);,using Numbers = int[];) and has to qualify it. For these aliases,UsingDirectiveSyntax.Nameis null.Fix: when
Nameis null, qualify each outermostNameSyntaxinside the alias target type (NamespaceOrType()). The existing symbol-qualification logic is extracted intoQualifyNameand reused unchanged.Test:
SA1200OutsideNamespaceCSharp12UnitTests.TestAliasAnyTypeInNamespaceIsMovedAndQualifiedAsync. It failed with the NRE before the fix.Analyzer cost: none. This is code-fix only.
Known limitations
extern alias ext; using Box = global::G<ext::Lib.C>;withusing Items = Box[];inside the namespace) is qualified asG<Lib.C>[], losing theext::qualifier.extern alias ext; global using Rows = ext::Lib.C[];) is expanded toglobal::Lib.C[][]whenusing Items = Rows[];is moved, also losing theext::qualifier.Both only matter when the referenced library is reachable solely through the extern alias.