mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Tests after disallowing some explicit payable conversions
This commit is contained in:
parent
2fb191175b
commit
fdaede9b3e
@ -18,7 +18,7 @@ contract C {
|
||||
assembly {
|
||||
y := x
|
||||
}
|
||||
address payable z = payable(y);
|
||||
address payable z = payable(address(y));
|
||||
assembly {
|
||||
r := z
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
contract test {
|
||||
function f() public {
|
||||
payable(0x12).send(1);
|
||||
payable(address(0x12)).send(1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 5878: (50-71): Failure condition of 'send' ignored. Consider using 'transfer' instead.
|
||||
// Warning 5878: (50-80): Failure condition of 'send' ignored. Consider using 'transfer' instead.
|
||||
|
@ -1,9 +1,9 @@
|
||||
contract C {
|
||||
function f() public pure returns (C c) {
|
||||
c = C(payable(2));
|
||||
c = C(payable(address(2)));
|
||||
}
|
||||
fallback() external payable {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 3628: (0-120): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
|
||||
// Warning 3628: (0-129): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
|
||||
|
@ -4,16 +4,12 @@ contract C {
|
||||
address a2 = address(bytes20(0));
|
||||
address a3 = address(this);
|
||||
|
||||
address payable a4 = payable(uint160(0));
|
||||
address payable a5 = payable(bytes20(0));
|
||||
address payable a6 = payable(this);
|
||||
|
||||
// Trivial conversions
|
||||
address payable a7 = payable(address(uint160(0)));
|
||||
address payable a8 = payable(address(bytes20(0)));
|
||||
address payable a9 = payable(address(this));
|
||||
address payable a4 = payable(address(uint160(0)));
|
||||
address payable a5 = payable(address(bytes20(0)));
|
||||
address payable a6 = payable(address(this));
|
||||
|
||||
a1; a2; a3; a4; a5; a6; a7; a8; a9;
|
||||
a1; a2; a3; a4; a5; a6;
|
||||
}
|
||||
|
||||
// to make payable(this) work
|
||||
|
@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
address payable a = address(0);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9574: (52-82): Type address is not implicitly convertible to expected type address payable.
|
@ -1,5 +1,5 @@
|
||||
contract C {
|
||||
function f(bytes20 x) public pure returns (address payable) {
|
||||
return payable(x);
|
||||
return payable(address(x));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
// We allow an exception for 0
|
||||
address payable a = payable(0);
|
||||
a = payable(1);
|
||||
a = payable(address(1));
|
||||
address payable b = payable(0x0123456789012345678901234567890123456789);
|
||||
b = payable(0x9876543210987654321098765432109876543210);
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
address payable a = payable(address(uint160(0)));
|
||||
address payable b = payable(address(bytes20(0)));
|
||||
address payable c = payable(address(2));
|
||||
// hex literal that is only 15 bytes long
|
||||
address payable d = payable(address(0x002190356cBB839Cbe05303d7705Fa));
|
||||
|
||||
uint160 a1 = uint160(address(payable(0)));
|
||||
bytes20 b1 = bytes20(address(payable(0)));
|
||||
|
||||
a; b; c; d; a1; b1;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
address payable a = payable(uint160(0));
|
||||
address payable b = payable(bytes20(0));
|
||||
address payable c = payable(2);
|
||||
// hex literal that is only 15 bytes long
|
||||
address payable d = payable(0x002190356cBB839Cbe05303d7705Fa);
|
||||
|
||||
// The opposite should also be disallowed
|
||||
uint160 a1 = uint160(payable(0));
|
||||
bytes20 b1 = bytes20(payable(0));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 9640: (72-91): Explicit type conversion not allowed from "uint160" to "address payable".
|
||||
// TypeError 9640: (121-140): Explicit type conversion not allowed from "bytes20" to "address payable".
|
||||
// TypeError 9640: (170-180): Explicit type conversion not allowed from "int_const 2" to "address payable".
|
||||
// TypeError 9640: (260-301): Explicit type conversion not allowed from "int_const 6807...(25 digits omitted)...4970" to "address payable".
|
||||
// TypeError 9640: (375-394): Explicit type conversion not allowed from "address payable" to "uint160".
|
||||
// TypeError 9640: (417-436): Explicit type conversion not allowed from "address payable" to "bytes20".
|
@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
// 0 is okay, because it's an exception
|
||||
address payable a = payable(0);
|
||||
|
||||
// address literals have type address
|
||||
address payable b = payable(0x00000000219ab540356cBB839Cbe05303d7705Fa);
|
||||
|
||||
address payable c = payable(address(2));
|
||||
|
||||
a; b; c;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
contract C {
|
||||
function f() public pure returns (C c) {
|
||||
c = C(payable(2));
|
||||
c = C(payable(address(2)));
|
||||
}
|
||||
receive() external payable {
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
contract C {
|
||||
function f(uint x) public pure returns (address payable) {
|
||||
return payable(uint160(x));
|
||||
return payable(address(uint160(x)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user