type consistency with boolean comparisons
bool b, bool a;
a == b should compile to OP_NUMEQUAL (rather than OP_EQUAL)
a != b should compile to OP_NUMNOTEQUAL (rather than OP_EQUAL OP_NOT)
thanks for opening this issue!
In the first case I don't see why it would matter to use OP_NUMEQUAL rather than OP_EQUAL (they are functionally the same in this case so what is the benefit of making the breaking change?)
the second case would indeed save one opcode 👍 I quickly confirmed the compiler behavior on the playground
Making breaking changes to the compiler is only something we want to do very infrequently
I stand corrected that both are functionally the same
OP_NUMEQUAL matters for cases like positive and negative zero, which are equal numerically but not when doing OP_EQUAL
I think the only way to get to negative zero is to use int(0x80) which could happen I guess
require(bool(int(0x80)) == false);
compiles to OP_0 OP_EQUALVERIFY which would return false
so
int negativeZero = int(0x80);
bool falsyBool = bool(negativeZero);
require(falsyBool == false); // this will fail because of OP_EQUALVERIFY instead of OP_NUMEQUAL
edit: this can also be done with bool's directly
contract Example() {
function transfer(bool test) {
if(test == false){
require(tx.outputs.length == 2);
} else {
require(tx.outputs.length == 1); // negative zero would end up in this case
}
}
}
Let's get back to this after we've resolved type casting quirks.