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 to #23472 - !boolean in query should convert to boolean == false rather than boolean != true where possible #23711

Merged
merged 1 commit into from
Dec 18, 2020

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Dec 17, 2020

When comparing something to bool constant, which is later negated we now flip the constant true -> false and false -> true, rather than flipping the operation from == to !=

Fixes #23472

@maumar maumar requested a review from a team December 17, 2020 04:17
@maumar maumar force-pushed the fix23472 branch 2 times, most recently from 4b4a30a to f45d186 Compare December 17, 2020 05:02
@smitpatel
Copy link
Member

Can you also add a test with !boolean alongside here 5b7f684#diff-d9f6f1a40210dca2fe5b3fc6ff8e3f54f9c27f46746915b34505a9327fe43008

So it verifies that it works with value converter also.

@maumar maumar force-pushed the fix23472 branch 3 times, most recently from 1b624e1 to 1ce7ef4 Compare December 17, 2020 22:32
…rather than boolean != true where possible

When comparing something to bool constant, which is later negated we now flip the constant true -> false and false -> true, rather than flipping the operation from == to !=
{
return _sqlExpressionFactory.MakeBinary(
ExpressionType.Equal,
_sqlExpressionFactory.Constant(!(bool)constant.Value!, constant.TypeMapping),
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that the value should be negated only if sqlBinaryOperand.OperatorType == ExpressionType.Equal
if sqlBinaryOperand.OperatorType == ExpressionType.NotEqual, the constant should be constructed with constant.Value (no negation) since the operator is already being negated

also, I am quite confident that the NotEqual case is dead code; would it make sense to remove it? (considering that it is wrong and unreachable)

Copy link
Member

Choose a reason for hiding this comment

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

/cc @maumar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense - good catch!

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened #33943

ranma42 added a commit to ranma42/efcore that referenced this pull request Jun 9, 2024
It is implemented incorrectly, namely as if the expression was `NOT(a == b)`
and it is currently unused.

See dotnet#23711 (review)
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.

!boolean in query should convert to boolean == false rather than boolean != true where possible
4 participants