G
GP
It appears to be a flaw in the specs, or I did not understand how it works.
7.11.2 User-defined conditional logical operators says that in order to
overload conditional logical operators && and || (which cannot be directly
overloaded in C#) you need to overload the true and false operators and the
compiler will convert expressions like (x && x) to T.op_False(x) ? x :
T.op_BitwiseAnd(x, y). However this results in evaluating the wrong logical
expression since
1 && 2 == op_False(1) ? 1 : op_BitwiseAnd(1, 2) == 0
Now, if I change the op_BitwiseAnd() operator to work as a op_LogicalAnd
then I'm breaking the bitwise And. Also having a bitwise operator acting
like a logical operator seems kind of a bad inconsistency in the language
specs.
Is there something I did not understand, or is there a fix planned for this?
--Gianluca
7.11.2 User-defined conditional logical operators says that in order to
overload conditional logical operators && and || (which cannot be directly
overloaded in C#) you need to overload the true and false operators and the
compiler will convert expressions like (x && x) to T.op_False(x) ? x :
T.op_BitwiseAnd(x, y). However this results in evaluating the wrong logical
expression since
1 && 2 == op_False(1) ? 1 : op_BitwiseAnd(1, 2) == 0
Now, if I change the op_BitwiseAnd() operator to work as a op_LogicalAnd
then I'm breaking the bitwise And. Also having a bitwise operator acting
like a logical operator seems kind of a bad inconsistency in the language
specs.
Is there something I did not understand, or is there a fix planned for this?
--Gianluca