Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RCS1146 #1098

Merged
merged 6 commits into from
Jun 27, 2023
Merged

Fix RCS1146 #1098

merged 6 commits into from
Jun 27, 2023

Conversation

jamesHargreaves12
Copy link
Contributor

If we have the following expression and the field F is a value type then we cannot apply RCS1146 as this will mean that a different overload of == is used (and one may not exist).

c != null && c.F == "someStr"

We know that the == operator exists and works correctly for in-built value types like int so the diagnostic can still be suggested for those cases.

@@ -274,6 +274,14 @@ static bool ExistsImplicitConversionToBoolean(INamedTypeSymbol typeSymbol)
case SyntaxKind.GreaterThanOrEqualExpression:
case SyntaxKind.EqualsExpression:
{
var leftTypeSymbol = semanticModel.GetTypeSymbol(((BinaryExpressionSyntax)expression).Left);
if (leftTypeSymbol.IsValueType && leftTypeSymbol.SpecialType is SpecialType.None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather use CSharpFacts.IsPredefinedType instead of is SpecialTypen.None.

@josefpihrt josefpihrt merged commit 16ff010 into dotnet:main Jun 27, 2023
@josefpihrt
Copy link
Collaborator

👍

Haarmees pushed a commit to Haarmees/Roslynator that referenced this pull request Oct 30, 2023
Co-authored-by: Josef Pihrt <josef@pihrt.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants