Closed haoyang9804 closed 1 week ago
int256 a = 22; int256 a2 = true ? int256(22) : int256(23);
int256 a = 22; int256 a2 = true ? int256(22) : int256(23);
Oh thx. I think it's a solution. But is it not a bug? I expect the type checker can infer the type of 22 and 23 in this scenario.
@haoyang9804 This behaviour is not a bug and is in fact the normal behaviour (see docs for reference). The type system does infer types in cases that are currently limited. However, we are aware of all the cases, the likes of above, that aren't covered well by the current type system and are working on bringing a better experience through the new type system in Solidity.
For now, I will be closing this issue given the above reasoning.
The following two statements are of the same functions:
However, the second statement throws an error with message:
Error: Type uint8 is not implicitly convertible to expected type int256
. Seems that Solidity compiler misunderstood the type of 22 and cannot take it as a int256 literal as it did for the first statement.This bug (or, this feature) is kind of confusing and causes a little inconvenience.