mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Restrict unary negation to signed integers.
This commit is contained in:
@@ -778,7 +778,7 @@ BOOST_AUTO_TEST_CASE(sign_extension)
|
||||
function run() public returns(uint256 y) {
|
||||
int64 x = -int32(0xff);
|
||||
if (x >= 0xff) return 0;
|
||||
return -uint256(x);
|
||||
return 0 - uint256(x);
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
@@ -9,7 +9,7 @@ contract C {
|
||||
returns (uint256 x1, uint256 x2, uint256 x3, uint256 x4)
|
||||
{
|
||||
a = -2;
|
||||
b = -uint8(a) * 2;
|
||||
b = (0 - uint8(a)) * 2;
|
||||
c = a * int8(120) * int8(121);
|
||||
x1 = uint256(a);
|
||||
x2 = b;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
contract test {
|
||||
function f() public pure {
|
||||
int x;
|
||||
uint y = uint(-x);
|
||||
-y;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 4907: (97-99): Unary operator - cannot be applied to type uint256
|
||||
Reference in New Issue
Block a user