Merge pull request #8994 from ethereum/fixInvertedBinaryOp

Fix type inversion for shift and exp operators.
This commit is contained in:
chriseth
2020-06-03 14:11:16 +02:00
committed by GitHub
12 changed files with 66 additions and 10 deletions
@@ -1,5 +1,5 @@
contract C {
function f() public pure returns (uint8 x) {
function f() public pure returns (uint x) {
uint8 y = uint8(2)**uint8(8);
return 0**y;
}
@@ -0,0 +1,16 @@
contract test {
function f(uint x) public pure returns (uint, int) {
uint a = 2 ** x;
int b = -2 ** x;
return (a, b);
}
}
// ----
// f(uint256): 0 -> 1, 1
// f(uint256): 1 -> 2, -2
// f(uint256): 2 -> 4, 4
// f(uint256): 13 -> 0x2000, -8192
// f(uint256): 113 -> 0x020000000000000000000000000000, -10384593717069655257060992658440192
// f(uint256): 114 -> 0x040000000000000000000000000000, 20769187434139310514121985316880384
// f(uint256): 1113 -> 0x00, 0
// f(uint256): 1114 -> 0x00, 0
@@ -5,4 +5,3 @@ contract test {
}
}
// ----
// Warning: (99-104): Result of exponentiation has type uint8 and thus might overflow. Silence this warning by converting the literal to the expected type.
@@ -5,4 +5,3 @@ contract test {
}
}
// ----
// Warning: (99-106): Result of shift has type uint8 and thus might overflow. Silence this warning by converting the literal to the expected type.
@@ -4,4 +4,4 @@ contract test {
}
}
// ----
// TypeError: (61-77): Operator ** not compatible with types int_const 3 and ufixed128x18
// TypeError: (61-77): Operator ** not compatible with types int_const 3 and ufixed128x18. Exponent is fractional.
@@ -4,4 +4,4 @@ contract test {
}
}
// ----
// TypeError: (61-78): Operator ** not compatible with types int_const 42 and fixed128x18
// TypeError: (61-78): Operator ** not compatible with types int_const 42 and fixed128x18. Exponent is fractional.
@@ -0,0 +1,7 @@
contract test {
function f() pure public returns(uint) {
uint x = 100;
return 10 << x;
}
}
// ----
@@ -7,4 +7,4 @@ contract test {
}
}
// ----
// UnimplementedFeatureError: Not yet implemented - FixedPointType.
// TypeError: (117-123): Operator % not compatible with types rational_const 1 / 2 and fixed128x18. Fractional literals not supported.