Skip to content

Commit

Permalink
Changed CT1712 to allow discards in parenthesized lambda expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
csdahlberg committed Aug 12, 2024
1 parent 0bf6106 commit 19e6ce8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ bool IsAllowableDiscard()
case SyntaxKind.ParenthesizedLambdaExpression:
case SyntaxKind.SimpleLambdaExpression:
return "_".Equals(parameterNode.Identifier.ValueText, StringComparison.OrdinalIgnoreCase);
case SyntaxKind.ParameterList:
return parameterNode.Parent.Parent?.IsKind(SyntaxKind.ParenthesizedLambdaExpression) == true
&& "_".Equals(parameterNode.Identifier.ValueText, StringComparison.OrdinalIgnoreCase);
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@ public void DoSomething()
{
var dictionary = new ConcurrentDictionary<int, string>();
dictionary.GetOrAdd(0, _ => "0");
dictionary.GetOrAdd(0, (_) => "0");
Action<object> action = _ => { };
Func<string, bool> func = (_) => true;
}
}
}
Expand All @@ -1050,7 +1053,7 @@ public void DoSomething()
}

[Fact]
public void ParameterWithDiscardNamesWhereNotAllowedProduceDiagnostics()
public void ParametersWithDiscardNamesWhereNotAllowedProduceDiagnostics()
{
string code = """
using System;
Expand Down

0 comments on commit 19e6ce8

Please sign in to comment.