diff --git a/docs/contracts/functions.rst b/docs/contracts/functions.rst index 279fec1f3..6aaa9d245 100644 --- a/docs/contracts/functions.rst +++ b/docs/contracts/functions.rst @@ -438,7 +438,7 @@ operations as long as there is enough gas passed on to it. // results in test.x becoming == 1 and test.y becoming 1. // If someone sends Ether to that contract, the receive function in TestPayable will be called. - require(address(test).send(2 ether)); + require(payable(test).send(2 ether)); // results in test.x becoming == 2 and test.y becoming 2 ether. return true; diff --git a/test/compilationTests/corion/module.sol b/test/compilationTests/corion/module.sol index ef0ffac21..1b52639d1 100644 --- a/test/compilationTests/corion/module.sol +++ b/test/compilationTests/corion/module.sol @@ -90,10 +90,10 @@ contract module { @newModuleAddress New module handler address */ require( moduleStatus != status.New && moduleStatus != status.Disconnected); - (bool _success, uint256 _balance) = abstractModuleHandler(moduleHandlerAddress).balanceOf(address(this)); + (bool _success, uint256 _balance) = abstractModuleHandler(moduleHandlerAddress).balanceOf(payable(this)); require( _success ); if ( _balance > 0 ) { - require( abstractModuleHandler(moduleHandlerAddress).transfer(address(this), newModuleAddress, _balance, false) ); + require( abstractModuleHandler(moduleHandlerAddress).transfer(payable(this), newModuleAddress, _balance, false) ); } if ( address(this).balance > 0 ) { require( newModuleAddress.send(address(this).balance) ); diff --git a/test/externalTests/solc-js/DAO/DAO.sol b/test/externalTests/solc-js/DAO/DAO.sol index c519bf70d..45778a3fc 100644 --- a/test/externalTests/solc-js/DAO/DAO.sol +++ b/test/externalTests/solc-js/DAO/DAO.sol @@ -724,11 +724,11 @@ contract DAO is DAOInterface, Token, TokenCreation { reward = address(DAOrewardAccount).balance < reward ? address(DAOrewardAccount).balance : reward; if(_toMembers) { - if (!DAOrewardAccount.payOut(address(dao.rewardAccount()), reward)) + if (!DAOrewardAccount.payOut(payable(dao.rewardAccount()), reward)) revert(); } else { - if (!DAOrewardAccount.payOut(address(dao), reward)) + if (!DAOrewardAccount.payOut(payable(dao), reward)) revert(); } DAOpaidOut[msg.sender] += reward; diff --git a/test/externalTests/solc-js/DAO/TokenCreation.sol b/test/externalTests/solc-js/DAO/TokenCreation.sol index cf0d27a53..64abf86ca 100644 --- a/test/externalTests/solc-js/DAO/TokenCreation.sol +++ b/test/externalTests/solc-js/DAO/TokenCreation.sol @@ -124,7 +124,7 @@ override returns (bool success) { if (block.timestamp > closingTime && !isFueled) { // Get extraBalance - will only succeed when called for the first time if (address(extraBalance).balance >= extraBalance.accumulatedInput()) - extraBalance.payOut(address(this), extraBalance.accumulatedInput()); + extraBalance.payOut(payable(this), extraBalance.accumulatedInput()); // Execute refund (bool success,) = msg.sender.call{value: weiGiven[msg.sender]}(""); diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index cea3a8847..3f5bf5d2d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1328,7 +1328,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses) } contract test { helper h; - constructor() payable { h = new helper(); address(h).send(5); } + constructor() payable { h = new helper(); payable(h).send(5); } function getBalance() public returns (uint256 myBalance, uint256 helperBalance) { myBalance = address(this).balance; helperBalance = address(h).balance; @@ -4640,7 +4640,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_transfer) revert("message"); } function f() public { - address(this).transfer(0); + payable(this).transfer(0); } } contract C { diff --git a/test/libsolidity/semanticTests/cleanup/cleanup_address_types_shortening.sol b/test/libsolidity/semanticTests/cleanup/cleanup_address_types_shortening.sol index f6dbdbc2f..9b9a695e1 100644 --- a/test/libsolidity/semanticTests/cleanup/cleanup_address_types_shortening.sol +++ b/test/libsolidity/semanticTests/cleanup/cleanup_address_types_shortening.sol @@ -18,7 +18,7 @@ contract C { assembly { y := x } - address payable z = address(y); + address payable z = payable(y); assembly { r := z } diff --git a/test/libsolidity/semanticTests/expressions/uncalled_address_transfer_send.sol b/test/libsolidity/semanticTests/expressions/uncalled_address_transfer_send.sol index 4511b9cb8..b7fe44beb 100644 --- a/test/libsolidity/semanticTests/expressions/uncalled_address_transfer_send.sol +++ b/test/libsolidity/semanticTests/expressions/uncalled_address_transfer_send.sol @@ -1,7 +1,7 @@ contract TransferTest { fallback() external payable { // This used to cause an ICE - address(this).transfer; + payable(this).transfer; } function f() pure public {} diff --git a/test/libsolidity/semanticTests/functionCall/send_zero_ether.sol b/test/libsolidity/semanticTests/functionCall/send_zero_ether.sol index 401f33f34..059d0878c 100644 --- a/test/libsolidity/semanticTests/functionCall/send_zero_ether.sol +++ b/test/libsolidity/semanticTests/functionCall/send_zero_ether.sol @@ -10,7 +10,7 @@ contract Main { function s() public returns (bool) { Receiver r = new Receiver(); - return address(r).send(0); + return payable(r).send(0); } } diff --git a/test/libsolidity/semanticTests/revertStrings/transfer.sol b/test/libsolidity/semanticTests/revertStrings/transfer.sol index 5d13f7d72..8ee6fd2e8 100644 --- a/test/libsolidity/semanticTests/revertStrings/transfer.sol +++ b/test/libsolidity/semanticTests/revertStrings/transfer.sol @@ -8,13 +8,13 @@ contract C { A a = new A(); receive() external payable {} function f() public { - address(a).transfer(1 wei); + payable(a).transfer(1 wei); } function h() public { - address(a).transfer(100 ether); + payable(a).transfer(100 ether); } function g() public view returns (uint) { - return address(this).balance; + return payable(this).balance; } } // ==== diff --git a/test/libsolidity/semanticTests/state/msg_sender.sol b/test/libsolidity/semanticTests/state/msg_sender.sol index 6348bb477..57c7fd5f3 100644 --- a/test/libsolidity/semanticTests/state/msg_sender.sol +++ b/test/libsolidity/semanticTests/state/msg_sender.sol @@ -1,5 +1,5 @@ contract C { - function f() public returns (address payable) { + function f() public returns (address) { return msg.sender; } } diff --git a/test/libsolidity/semanticTests/state/tx_origin.sol b/test/libsolidity/semanticTests/state/tx_origin.sol index caa27d180..34f19f616 100644 --- a/test/libsolidity/semanticTests/state/tx_origin.sol +++ b/test/libsolidity/semanticTests/state/tx_origin.sol @@ -1,5 +1,5 @@ contract C { - function f() public returns (address payable) { + function f() public returns (address) { return tx.origin; } } diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/466_does_not_error_transfer_payable_fallback.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/466_does_not_error_transfer_payable_fallback.sol index 47dbb3c7b..642ae8360 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/466_does_not_error_transfer_payable_fallback.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/466_does_not_error_transfer_payable_fallback.sol @@ -9,7 +9,7 @@ contract B { A a; fallback() external { - address(a).transfer(100); + payable(a).transfer(100); } } // ---- diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol index 7afc3fed8..a36aeed86 100644 --- a/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol +++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/535_address_overload_resolution.sol @@ -4,7 +4,7 @@ contract C { return 1; } function transfer(uint amount) public { - address(this).transfer(amount); // to avoid pureness warning + payable(this).transfer(amount); // to avoid pureness warning } receive() payable external { } diff --git a/test/libsolidity/syntaxTests/types/address/address_in_struct_fine.sol b/test/libsolidity/syntaxTests/types/address/address_in_struct_fine.sol index 11d5e8677..6759bc11d 100644 --- a/test/libsolidity/syntaxTests/types/address/address_in_struct_fine.sol +++ b/test/libsolidity/syntaxTests/types/address/address_in_struct_fine.sol @@ -13,8 +13,8 @@ contract B { } S s; function f() public { - s.a = address(this); + s.a = payable(this); } receive() external payable { } -} \ No newline at end of file +} diff --git a/test/libsolidity/syntaxTests/types/address/address_to_contract_receive.sol b/test/libsolidity/syntaxTests/types/address/address_to_contract_receive.sol index 282985a77..75bd25376 100644 --- a/test/libsolidity/syntaxTests/types/address/address_to_contract_receive.sol +++ b/test/libsolidity/syntaxTests/types/address/address_to_contract_receive.sol @@ -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 { } diff --git a/test/libsolidity/syntaxTests/types/address/address_uint_bytes20_this.sol b/test/libsolidity/syntaxTests/types/address/address_uint_bytes20_this.sol new file mode 100644 index 000000000..4c62fa763 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_uint_bytes20_this.sol @@ -0,0 +1,23 @@ +contract C { + function f() public view { + address a1 = address(uint160(0)); + 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)); + + a1; a2; a3; a4; a5; a6; a7; a8; a9; + } + + // to make payable(this) work + receive() payable external { + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/address_uint_bytes20_this_to_payable_err.sol b/test/libsolidity/syntaxTests/types/address/address_uint_bytes20_this_to_payable_err.sol new file mode 100644 index 000000000..37f087e5b --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_uint_bytes20_this_to_payable_err.sol @@ -0,0 +1,11 @@ +contract C { + function f() public pure { + address payable a = address(uint160(0)); + address payable b = address(bytes20(0)); + address payable c = address(this); + } +} +// ---- +// TypeError 9574: (52-91): Type address is not implicitly convertible to expected type address payable. +// TypeError 9574: (101-140): Type address is not implicitly convertible to expected type address payable. +// TypeError 9574: (150-183): Type address is not implicitly convertible to expected type address payable. diff --git a/test/libsolidity/syntaxTests/types/address/bytes_to_payable_address.sol b/test/libsolidity/syntaxTests/types/address/bytes_to_payable_address.sol index 5b6a6714d..f4912c8a6 100644 --- a/test/libsolidity/syntaxTests/types/address/bytes_to_payable_address.sol +++ b/test/libsolidity/syntaxTests/types/address/bytes_to_payable_address.sol @@ -1,5 +1,5 @@ contract C { function f(bytes20 x) public pure returns (address payable) { - return address(x); + return payable(x); } } diff --git a/test/libsolidity/syntaxTests/types/address/contract_payable_fallback_to_payable_address.sol b/test/libsolidity/syntaxTests/types/address/contract_payable_fallback_to_payable_address.sol index 66da36221..2d4ae3a72 100644 --- a/test/libsolidity/syntaxTests/types/address/contract_payable_fallback_to_payable_address.sol +++ b/test/libsolidity/syntaxTests/types/address/contract_payable_fallback_to_payable_address.sol @@ -1,6 +1,6 @@ contract C { function f() public view { - address payable a = address(this); + address payable a = payable(this); a; } fallback() external payable { diff --git a/test/libsolidity/syntaxTests/types/address/contract_receive_to_payable_address.sol b/test/libsolidity/syntaxTests/types/address/contract_receive_to_payable_address.sol index 7c308b39a..cf25a618a 100644 --- a/test/libsolidity/syntaxTests/types/address/contract_receive_to_payable_address.sol +++ b/test/libsolidity/syntaxTests/types/address/contract_receive_to_payable_address.sol @@ -1,6 +1,6 @@ contract C { function f() public view { - address payable a = address(this); + address payable a = payable(this); a; } receive() external payable { diff --git a/test/libsolidity/syntaxTests/types/address/payable_conversion.sol b/test/libsolidity/syntaxTests/types/address/payable_conversion.sol new file mode 100644 index 000000000..ce7c9078a --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/payable_conversion.sol @@ -0,0 +1,29 @@ +contract C { + function f() public { + address payable a = payable(address(new D())); + address payable b = payable(new E()); + address payable c = payable(new F()); + + a; + b; + c; + } +} + +// A contract that cannot receive Ether +contract D {} + +// A contract that can receive Ether +contract E { + receive() external payable { + } +} + +// A contract that can receive Ether using the fallback +contract F { + fallback() external payable { + + } +} + +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/payable_conversion_err.sol b/test/libsolidity/syntaxTests/types/address/payable_conversion_err.sol new file mode 100644 index 000000000..28bb52e23 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/payable_conversion_err.sol @@ -0,0 +1,17 @@ +contract C { + function f() public { + address payable a = address(new D()); + + // This conversion makes no sense anyway. + address payable b = address(D); + } +} + +contract D { + receive() external payable { + } +} +// ---- +// TypeError 9574: (47-83): Type address is not implicitly convertible to expected type address payable. +// TypeError 9640: (164-174): Explicit type conversion not allowed from "type(contract D)" to "address". +// TypeError 9574: (144-174): Type address is not implicitly convertible to expected type address payable. diff --git a/test/libsolidity/syntaxTests/types/address/payable_to_contract_receive.sol b/test/libsolidity/syntaxTests/types/address/payable_to_contract_receive.sol new file mode 100644 index 000000000..282985a77 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/payable_to_contract_receive.sol @@ -0,0 +1,8 @@ +contract C { + function f() public pure returns (C c) { + c = C(payable(2)); + } + receive() external payable { + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/uint_to_payable_address.sol b/test/libsolidity/syntaxTests/types/address/uint_to_payable_address.sol index 412201671..7fa3fbcf0 100644 --- a/test/libsolidity/syntaxTests/types/address/uint_to_payable_address.sol +++ b/test/libsolidity/syntaxTests/types/address/uint_to_payable_address.sol @@ -1,5 +1,5 @@ contract C { function f(uint x) public pure returns (address payable) { - return address(uint160(x)); + return payable(uint160(x)); } } diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol index f828a0cf1..225a954cc 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions.sol @@ -1,8 +1,8 @@ contract C { function f() public { - address(this).transfer(1); - require(address(this).send(2)); - selfdestruct(address(this)); + payable(this).transfer(1); + require(payable(this).send(2)); + selfdestruct(payable(this)); (bool success,) = address(this).delegatecall(""); require(success); (success,) = address(this).call(""); diff --git a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol index ffd412375..000f5b009 100644 --- a/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol +++ b/test/libsolidity/syntaxTests/viewPureChecker/builtin_functions_view_fail.sol @@ -1,12 +1,12 @@ contract C { function f() view public { - address(this).transfer(1); + payable(this).transfer(1); } function g() view public { - require(address(this).send(2)); + require(payable(this).send(2)); } function h() view public { - selfdestruct(address(this)); + selfdestruct(payable(this)); } function i() view public { (bool success,) = address(this).delegatecall("");