-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Conversation
4b4a30a
to
f45d186
Compare
Can you also add a test with !boolean alongside here 5b7f684#diff-d9f6f1a40210dca2fe5b3fc6ff8e3f54f9c27f46746915b34505a9327fe43008 So it verifies that it works with value converter also. |
1b624e1
to
1ce7ef4
Compare
…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), |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @maumar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense - good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #33943
It is implemented incorrectly, namely as if the expression was `NOT(a == b)` and it is currently unused. See dotnet#23711 (review)
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