Skip to content

Commit 8d6262e

Browse files
committed
#3279 Introduce test case reproducing NRE
1 parent 23db6c0 commit 8d6262e

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,5 +880,57 @@ public class TestClass
880880

881881
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
882882
}
883+
884+
[Fact]
885+
[WorkItem(3279, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3279")]
886+
public async Task TestDelegateUsedAsSecondNamedArgumentAsync()
887+
{
888+
var testCode = @"
889+
using System;
890+
using System.Linq;
891+
public class TypeName
892+
{
893+
public void Test()
894+
{
895+
string[] capture = new string[] { ""test"" };
896+
Test2(resolve: delegate
897+
{
898+
return capture.Single(v => v == ""test"");
899+
});
900+
}
901+
902+
private void Test2(string description = null, Func<object, string> resolve = null)
903+
{
904+
resolve(0);
905+
}
906+
}";
907+
908+
string fixedCode = @"
909+
using System;
910+
using System.Linq;
911+
public class TypeName
912+
{
913+
public void Test()
914+
{
915+
string[] capture = new string[] { ""test"" };
916+
Test2(resolve: arg =>
917+
{
918+
return capture.Single(v => v == ""test"");
919+
});
920+
}
921+
922+
private void Test2(string description = null, Func<object, string> resolve = null)
923+
{
924+
resolve(0);
925+
}
926+
}";
927+
928+
var expected = new[]
929+
{
930+
Diagnostic().WithSpan(9, 24, 9, 32),
931+
};
932+
933+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
934+
}
883935
}
884936
}

0 commit comments

Comments
 (0)