Skip to content

Commit dfc58c7

Browse files
committed
#3279 Add test verifying that analysis won't crash despite compilation error
1 parent ee714c0 commit dfc58c7

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,5 +932,36 @@ private void Test2(string description = null, Func<object, string> resolve = nul
932932

933933
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
934934
}
935+
936+
[Fact]
937+
[WorkItem(3279, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3279")]
938+
public async Task VerifyThatUnknownNamedParameterWontCauseCrashAsync()
939+
{
940+
var testCode = @"
941+
using System;
942+
using System.Linq;
943+
public class TypeName
944+
{
945+
public void Test()
946+
{
947+
Test2(unknownParam: delegate
948+
{
949+
return """";
950+
});
951+
}
952+
953+
private void Test2(string description = null, Func<object, string> resolve = null)
954+
{
955+
resolve(0);
956+
}
957+
}";
958+
959+
var expected = DiagnosticResult.CompilerError("CS1739")
960+
.WithMessage("The best overload for 'Test2' does not have a parameter named 'unknownParam'")
961+
.WithSpan(8, 15, 8, 27)
962+
.WithArguments("Test2", "unknownParam");
963+
964+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
965+
}
935966
}
936967
}

0 commit comments

Comments
 (0)