11// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4- #nullable disable
5-
64namespace StyleCop . Analyzers . Test . CSharp8 . SpacingRules
75{
86 using System . Threading ;
@@ -16,6 +14,65 @@ namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
1614
1715 public partial class SA1011CSharp8UnitTests : SA1011CSharp7UnitTests
1816 {
17+ [ Fact ]
18+ [ WorkItem ( 3006 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3006" ) ]
19+ public async Task VerifyNullableArrayAnnotationsAsync ( )
20+ {
21+ var testCode = @"#nullable enable
22+ namespace TestNamespace
23+ {
24+ public class TestClass
25+ {
26+ private string[]? field1;
27+ private string[]?[]? field2;
28+ private string?[][]? field3;
29+
30+ public string[]? Property1 => field1;
31+
32+ public string[]?[]? Property2
33+ {
34+ get
35+ {
36+ return new string[]?[] { field1, field2?[0] };
37+ }
38+ }
39+
40+ public string?[] Method(string?[]? values, string[]?[]? other)
41+ {
42+ return values ?? new string?[] { null, other?[0]?[0] };
43+ }
44+ }
45+ }
46+ " ;
47+
48+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
49+ }
50+
51+ [ Fact ]
52+ [ WorkItem ( 3006 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3006" ) ]
53+ public async Task VerifyNullForgivingAfterElementAccessAndArrayCreationAsync ( )
54+ {
55+ var testCode = @"#nullable enable
56+ namespace TestNamespace
57+ {
58+ public class TestClass
59+ {
60+ public string GetValue(string[]? values)
61+ {
62+ return values![0]!;
63+ }
64+
65+ public int GetLength(string?[] items)
66+ {
67+ return new string?[0]!.Length + items[0]! .Length;
68+ }
69+ }
70+ }
71+ " ;
72+
73+ await VerifyCSharpDiagnosticAsync ( testCode , DiagnosticResult . EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
74+ }
75+
1976 /// <summary>
2077 /// Verify that declaring a null reference type works for arrays.
2178 /// </summary>
0 commit comments