Describe the bug
Smart contract return type is irregular when return Boolean result, sometimes it's 1, sometimes it's true.
like:
public class Example : SmartContract
{
public static bool main(int i, int j)
{
return i != j && (i > 0 || j < 2);
}
}
If invoked with i = 0 and j = 1, I get a Boolean result type. If I invoke with i = 1 and j = 1 I get an Integer, the results are correct, but the type is irregular.
Expected behavior
Always return Boolean.
Platform:
This should be due to the following reasons:
For example, in IL Code, about the instruction Ceq,
Compare two values. If the two values are equal, the integer value 1 (int32) is pushed onto the calculation stack; Otherwise, 0 (int32) is pushed onto the compute stack.
But in NeoVM,the corresponding opcode is NUMEQUAL,
case OpCode.NUMEQUAL:
{
var x2 = Pop().GetInteger();
var x1 = Pop().GetInteger();
Push(x1 == x2);
break;
}
it will push a bool value (true or false).
So IL uses 1 and 0 for true and false, but NeoVM doesn't.
It causes the return value type to be irregular.
for the vm, an integer 1 or true it's, more or less, the same, that's why we have the Abi, we sould process the output
for the vm, an integer 1 or true it's, more or less, the same, that's why we have the Abi, we sould process the output
That's exactly the problem: the NeoVM returns more or less something, and the ABI might say something else. Inconsistency as it's best. 😃 🤣
I think the compiler should take care of that...
I think the compiler should take care of that...
of course, anything than can be fixed, must be fixed :)
NeoVM returns more or less something, and the ABI might say something else
Well, it can also be viewed as an output companion of #1891 which is about inputs.
Most helpful comment
of course, anything than can be fixed, must be fixed :)