@@ -35,5 +35,61 @@ public struct Foo<T>
3535
3636 await VerifyCSharpFixAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
3737 }
38+
39+ /// <summary>
40+ /// Verifies that nullable reference type annotations following closing generic brackets do not produce diagnostics.
41+ /// </summary>
42+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
43+ [ Fact ]
44+ [ WorkItem ( 3006 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3006" ) ]
45+ public async Task TestNullableReferenceTypeAnnotationsAsync ( )
46+ {
47+ const string testCode = @"#nullable enable
48+ using System.Collections.Generic;
49+
50+ public class TestClass
51+ {
52+ private List<string?>? names;
53+ private Dictionary<string, List<object?>?>? items;
54+
55+ public IReadOnlyList<List<string?>?>? Property { get; }
56+
57+ public void TestMethod()
58+ {
59+ List<(string? key, List<string?>? values)>? local = null;
60+ List<string?>?[]? jagged = null;
61+ }
62+ }
63+ " ;
64+
65+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
66+ }
67+
68+ /// <summary>
69+ /// Verifies that nullable reference type constraints involving generic types are handled without diagnostics.
70+ /// </summary>
71+ /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
72+ [ Fact ]
73+ [ WorkItem ( 3006 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3006" ) ]
74+ public async Task TestNullableReferenceTypeConstraintsAsync ( )
75+ {
76+ const string testCode = @"#nullable enable
77+ using System.Collections.Generic;
78+
79+ public class ConstraintClass<T> where T : class
80+ {
81+ public void TestMethod<TValue>(TValue? value)
82+ where TValue : class, IEnumerable<T?>?
83+ {
84+ if (value is List<T?> items)
85+ {
86+ _ = items;
87+ }
88+ }
89+ }
90+ " ;
91+
92+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
93+ }
3894 }
3995}
0 commit comments