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

MSTEST0037 (proper assert analyzer): Don't report for user defined equality operators #4456

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ private static bool IsIsNotNullPattern(IOperation operation, [NotNullWhen(true)]
private static bool IsEqualsNullBinaryOperator(IOperation operation, [NotNullWhen(true)] out SyntaxNode? expressionUnderTest)
{
if (operation is IBinaryOperation { OperatorKind: BinaryOperatorKind.Equals, RightOperand: { } rightOperand } binaryOperation &&
binaryOperation.OperatorMethod is not { MethodKind: MethodKind.UserDefinedOperator } &&
rightOperand.WalkDownConversion() is ILiteralOperation { ConstantValue: { HasValue: true, Value: null } })
{
expressionUnderTest = binaryOperation.LeftOperand.Syntax;
Expand All @@ -221,6 +222,7 @@ private static bool IsEqualsNullBinaryOperator(IOperation operation, [NotNullWhe
private static bool IsNotEqualsNullBinaryOperator(IOperation operation, [NotNullWhen(true)] out SyntaxNode? expressionUnderTest)
{
if (operation is IBinaryOperation { OperatorKind: BinaryOperatorKind.NotEquals, RightOperand: { } rightOperand } binaryOperation &&
binaryOperation.OperatorMethod is not { MethodKind: MethodKind.UserDefinedOperator } &&
rightOperand.WalkDownConversion() is ILiteralOperation { ConstantValue: { HasValue: true, Value: null } })
{
expressionUnderTest = binaryOperation.LeftOperand.Syntax;
Expand Down Expand Up @@ -253,7 +255,8 @@ private static EqualityCheckStatus RecognizeEqualityCheck(IOperation operation,
toBecomeActual = isPattern1.Value.Syntax;
return EqualityCheckStatus.Equals;
}
else if (operation is IBinaryOperation { OperatorKind: BinaryOperatorKind.Equals } binaryOperation1)
else if (operation is IBinaryOperation { OperatorKind: BinaryOperatorKind.Equals } binaryOperation1 &&
binaryOperation1.OperatorMethod is not { MethodKind: MethodKind.UserDefinedOperator })
{
// This is quite arbitrary. We can do extra checks to see which one (if any) looks like a "constant" and make it the expected.
toBecomeExpected = binaryOperation1.RightOperand.Syntax;
Expand All @@ -266,7 +269,8 @@ private static EqualityCheckStatus RecognizeEqualityCheck(IOperation operation,
toBecomeActual = isPattern2.Value.Syntax;
return EqualityCheckStatus.NotEquals;
}
else if (operation is IBinaryOperation { OperatorKind: BinaryOperatorKind.NotEquals } binaryOperation2)
else if (operation is IBinaryOperation { OperatorKind: BinaryOperatorKind.NotEquals } binaryOperation2 &&
binaryOperation2.OperatorMethod is not { MethodKind: MethodKind.UserDefinedOperator })
{
// This is quite arbitrary. We can do extra checks to see which one (if any) looks like a "constant" and make it the expected.
toBecomeExpected = binaryOperation2.RightOperand.Syntax;
Expand Down
Loading
Loading