Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48addde

Browse files
authored
Merge pull request #1012 from Muppets/CC0020-cannot-be-used
Fixes #930 CC0020 cannot be used when types are declared
2 parents d1561e7 + 9ccc2bb commit 48addde

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/CSharp/CodeCracker/Style/ConvertLambdaExpressionToMethodGroupAnalyzer.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ internal static InvocationExpressionSyntax GetInvocationIfAny(SyntaxNode node)
6565
: (node as ParenthesizedLambdaExpressionSyntax)?.Body;
6666

6767
var invocation = body as InvocationExpressionSyntax;
68-
if (invocation != null) return invocation;
68+
69+
if (invocation != null)
70+
{
71+
if (invocation.Expression is GenericNameSyntax && (((GenericNameSyntax)invocation.Expression).TypeArgumentList.Arguments.Count > 0)) return null;
72+
73+
return invocation;
74+
}
6975

7076
var possibleBlock = body as BlockSyntax;
7177
if (possibleBlock == null || possibleBlock.Statements.Count != 1) return null;

test/CSharp/CodeCracker.Test/Style/ConvertLambdaExpressionToMethodGroupTests.cs

+18
Original file line numberDiff line numberDiff line change
@@ -598,5 +598,23 @@ public static Task<TResult> Finally<TResult>(this Task<TResult> task, Func<Task<
598598
";
599599
await VerifyCSharpHasNoDiagnosticsAsync(oldCode);
600600
}
601+
602+
[Fact]
603+
public async Task DoNotCreateDiagnosticWhenSubstitutionMayBreakTypeConversion()
604+
{
605+
const string oldCode = @"
606+
using System.Linq;
607+
class Foo
608+
{
609+
void M()
610+
{
611+
var xs = new System.Collections.Generic.List<int>();
612+
xs.Select(x => Func<int>(x));
613+
}
614+
object Func<T>(object x) => x;
615+
}";
616+
await VerifyCSharpHasNoDiagnosticsAsync(oldCode);
617+
}
618+
601619
}
602620
}

0 commit comments

Comments
 (0)