mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix type inversion for shift and exp operators.
This commit is contained in:
@@ -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.
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+1
-1
@@ -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.
|
||||
|
||||
+7
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user