Skip to content

Commit e6469ba

Browse files
authored
Merge pull request #2807 from pdelvo/sa1130nre
Fix that SA1130 crashes on an overload resolution failure
2 parents 1d8eb55 + b3262df commit e6469ba

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,5 +380,29 @@ public static void TestMethod2(TestDelegate testDelegate)
380380

381381
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
382382
}
383+
384+
[Fact]
385+
public async Task TestOverloadResolutionFailureAsync()
386+
{
387+
var testCode = @"
388+
using System;
389+
using System.Linq.Expressions;
390+
public class TypeName
391+
{
392+
public void Test(string argument)
393+
{
394+
395+
}
396+
397+
public void Test()
398+
{
399+
Test(delegate { });
400+
}
401+
}";
402+
403+
var expected = DiagnosticResult.CompilerError("CS1660").WithLocation(13, 14);
404+
405+
await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
406+
}
383407
}
384408
}

StyleCop.Analyzers/StyleCop.Analyzers/ReadabilityRules/SA1130UseLambdaSyntax.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ private static bool HandleMethodInvocation(SemanticModel semanticModel, Anonymou
9999
if (originalInvocationExpression != null)
100100
{
101101
SymbolInfo originalSymbolInfo = semanticModel.GetSymbolInfo(originalInvocationExpression);
102+
103+
if (originalSymbolInfo.Symbol == null)
104+
{
105+
// The most likely cause for this is an overload resolution failure.
106+
return false;
107+
}
108+
102109
Location location = originalInvocationExpression.GetLocation();
103110

104111
var argumentIndex = argumentListSyntax.Arguments.IndexOf(argumentSyntax);

0 commit comments

Comments
 (0)