mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow explicit conversions from negative literals to `address`
This commit is contained in:
committed by
hrkrshnn
parent
b401093679
commit
a309669f75
@@ -1,7 +1,7 @@
|
||||
contract Test {
|
||||
function test() public returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); }
|
||||
function test() public returns (uint ret) { return uint(address(uint128(0x11223344556677889900112233445566778899001122))); }
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 0x0000000000000000000000003344556677889900112233445566778899001122
|
||||
// test() -> 158887387085137674884660775897412931874
|
||||
|
||||
@@ -17,9 +17,9 @@ contract C {
|
||||
assert(t == 200);
|
||||
int256 v = int256(bytes32(uint256(2**255 + 10)));
|
||||
assert(v == -(2**255) + 10);
|
||||
int160 a = int160(address(-1));
|
||||
int160 a = int160(address(type(uint160).max));
|
||||
assert(a == -1);
|
||||
int160 b = int160(address(2**159 + 10));
|
||||
int160 b = int160(address(uint(2**159 + 10)));
|
||||
assert(b == -(2**159) + 10);
|
||||
D d;
|
||||
int160 e = int160(address(d));
|
||||
@@ -42,7 +42,7 @@ contract C {
|
||||
assert(w == 2**256 - 2);
|
||||
bytes4 b = bytes4(uint32(-2));
|
||||
assert(uint32(b) == uint32(2**32 - 2));
|
||||
address a = address(-1);
|
||||
address a = address(type(uint160).max);
|
||||
assert(uint160(a) == uint160(2**160 - 1));
|
||||
address c = address(0);
|
||||
assert(uint160(c) == 0);
|
||||
@@ -71,4 +71,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 8364: (1304-1305): Assertion checker does not yet implement type type(enum E)
|
||||
// Warning 8364: (1340-1341): Assertion checker does not yet implement type type(enum E)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
contract C {
|
||||
function f() public pure returns (address) {
|
||||
return address(2**160 -1);
|
||||
}
|
||||
function g() public pure returns (address) {
|
||||
return address(uint(-1));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,15 @@
|
||||
contract C {
|
||||
function f() public pure returns (address) {
|
||||
return address(-1);
|
||||
}
|
||||
function g() public pure returns (address) {
|
||||
return -1;
|
||||
}
|
||||
function h() public pure returns (address) {
|
||||
return address(2**160);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9640: (77-88): Explicit type conversion not allowed from "int_const -1" to "address".
|
||||
// TypeError 6359: (160-162): Return argument type int_const -1 is not implicitly convertible to expected type (type of first return variable) address.
|
||||
// TypeError 9640: (225-240): Explicit type conversion not allowed from "int_const 1461...(41 digits omitted)...2976" to "address".
|
||||
Reference in New Issue
Block a user