Restrict unary negation to signed integers.

This commit is contained in:
chriseth
2020-09-17 15:01:53 +02:00
parent e4231b879b
commit aa7a6922e7
6 changed files with 20 additions and 8 deletions
+1 -1
View File
@@ -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