diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-09-05 23:59:55 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2018-09-13 21:15:49 +0800 |
commit | 12aaca16458861e9b622818d49a82c1a7026594e (patch) | |
tree | 7b51c4893c6646134618b6c20574317ec014f225 /test/libsolidity/syntaxTests | |
parent | 9214c7c34f5e4501a50cb29de964bbf04131f9a3 (diff) | |
download | dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.tar.gz dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.tar.zst dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.zip |
Add payable and non-payable state mutability to AddressType.
Diffstat (limited to 'test/libsolidity/syntaxTests')
31 files changed, 263 insertions, 7 deletions
diff --git a/test/libsolidity/syntaxTests/parsing/address_in_struct.sol b/test/libsolidity/syntaxTests/parsing/address_in_struct.sol new file mode 100644 index 00000000..68049b50 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/address_in_struct.sol @@ -0,0 +1,6 @@ +contract C { + struct S { + address payable a; + address b; + } +} diff --git a/test/libsolidity/syntaxTests/parsing/address_nonpayable.sol b/test/libsolidity/syntaxTests/parsing/address_nonpayable.sol new file mode 100644 index 00000000..fea67138 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/address_nonpayable.sol @@ -0,0 +1,7 @@ +contract C { + address a; + function f(address b) public pure returns (address c) { + address d = b; + return d; + } +} diff --git a/test/libsolidity/syntaxTests/parsing/address_payable.sol b/test/libsolidity/syntaxTests/parsing/address_payable.sol new file mode 100644 index 00000000..c29ae1b7 --- /dev/null +++ b/test/libsolidity/syntaxTests/parsing/address_payable.sol @@ -0,0 +1,7 @@ +contract C { + address payable a; + function f(address payable b) public pure returns (address payable c) { + address payable d = b; + return d; + } +} diff --git a/test/libsolidity/syntaxTests/types/address/address_abi_decode.sol b/test/libsolidity/syntaxTests/types/address/address_abi_decode.sol new file mode 100644 index 00000000..7be61ad2 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_abi_decode.sol @@ -0,0 +1,6 @@ +contract C { + function f(bytes memory b) public pure returns (address payable) { + (address payable c) = abi.decode(b, (address)); + return c; + } +}
\ No newline at end of file diff --git a/test/libsolidity/syntaxTests/types/address/address_constant.sol b/test/libsolidity/syntaxTests/types/address/address_constant.sol new file mode 100644 index 00000000..0b1af991 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_constant.sol @@ -0,0 +1,7 @@ +contract C { + address constant a = address(0); + address payable constant b = address(0); + function f() public pure returns (address, address) { + return (a,b); + } +} diff --git a/test/libsolidity/syntaxTests/types/address/address_constant_assignment.sol b/test/libsolidity/syntaxTests/types/address/address_constant_assignment.sol new file mode 100644 index 00000000..da17ae33 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_constant_assignment.sol @@ -0,0 +1,11 @@ +contract C { + address constant a = address(0); + address payable constant b = address(0); + function f() public { + a = address(0); + b = address(0); + } +} +// ---- +// TypeError: (129-130): Cannot assign to a constant variable. +// TypeError: (153-154): Cannot assign to a constant variable. diff --git a/test/libsolidity/syntaxTests/types/address/address_in_struct_fail.sol b/test/libsolidity/syntaxTests/types/address/address_in_struct_fail.sol new file mode 100644 index 00000000..9a5b2abb --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_in_struct_fail.sol @@ -0,0 +1,11 @@ +contract A { + struct S { + address payable a; + } + S s; + function f() public { + s.a = address(this); + } +} +// ---- +// TypeError: (110-123): Type address is not implicitly convertible to expected type address payable. diff --git a/test/libsolidity/syntaxTests/types/address/address_in_struct_fine.sol b/test/libsolidity/syntaxTests/types/address/address_in_struct_fine.sol new file mode 100644 index 00000000..5519f0ef --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_in_struct_fine.sol @@ -0,0 +1,20 @@ +contract A { + struct S { + address a; + } + S s; + function f() public { + s.a = address(this); + } +} +contract B { + struct S { + address payable a; + } + S s; + function f() public { + s.a = address(this); + } + function() external payable { + } +}
\ No newline at end of file diff --git a/test/libsolidity/syntaxTests/types/address/address_nonpayable_selfdestruct.sol b/test/libsolidity/syntaxTests/types/address/address_nonpayable_selfdestruct.sol new file mode 100644 index 00000000..cc680ff3 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_nonpayable_selfdestruct.sol @@ -0,0 +1,7 @@ +contract C { + function f(address a) public { + selfdestruct(a); + } +} +// ---- +// TypeError: (69-70): Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested. diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_external_overload.sol b/test/libsolidity/syntaxTests/types/address/address_payable_external_overload.sol new file mode 100644 index 00000000..875532c4 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_payable_external_overload.sol @@ -0,0 +1,7 @@ +contract C { + function f(address) external pure {} + function f(address payable) external pure {} + +} +// ---- +// TypeError: (58-102): Function overload clash during conversion to external types for arguments. diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_internal_overload_nonpayable.sol b/test/libsolidity/syntaxTests/types/address/address_payable_internal_overload_nonpayable.sol new file mode 100644 index 00000000..65600544 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_payable_internal_overload_nonpayable.sol @@ -0,0 +1,10 @@ +contract C { + function f(address payable) internal pure {} + function f(address) internal pure returns (uint) {} + function g() internal pure { + address a = address(0); + uint b = f(a); // TODO: should this be valid? + b; + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_internal_overload_payable.sol b/test/libsolidity/syntaxTests/types/address/address_payable_internal_overload_payable.sol new file mode 100644 index 00000000..84142a31 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_payable_internal_overload_payable.sol @@ -0,0 +1,10 @@ +contract C { + function f(address payable) internal pure {} + function f(address) internal pure {} + function g() internal pure { + address payable a = address(0); + f(a); + } +} +// ---- +// TypeError: (184-185): No unique declaration found after argument-dependent lookup. diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_memory_array_conversion.sol b/test/libsolidity/syntaxTests/types/address/address_payable_memory_array_conversion.sol new file mode 100644 index 00000000..ec58170b --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_payable_memory_array_conversion.sol @@ -0,0 +1,11 @@ +contract C { + function f() public pure { + address payable[] memory a = new address payable[](4); + address[] memory b = new address[](4); + a = b; + b = a; + } +} +// ---- +// TypeError: (166-167): Type address[] memory is not implicitly convertible to expected type address payable[] memory. +// TypeError: (181-182): Type address payable[] memory is not implicitly convertible to expected type address[] memory. diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_public_overload.sol b/test/libsolidity/syntaxTests/types/address/address_payable_public_overload.sol new file mode 100644 index 00000000..839abc26 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_payable_public_overload.sol @@ -0,0 +1,7 @@ +contract C { + function f(address) public pure {} + function f(address payable) public pure {} + +} +// ---- +// TypeError: (56-98): Function overload clash during conversion to external types for arguments. diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_selfdestruct.sol b/test/libsolidity/syntaxTests/types/address/address_payable_selfdestruct.sol new file mode 100644 index 00000000..bdf43be7 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_payable_selfdestruct.sol @@ -0,0 +1,5 @@ +contract C { + function f(address payable a) public { + selfdestruct(a); + } +} diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_storage_array_conversion.sol b/test/libsolidity/syntaxTests/types/address/address_payable_storage_array_conversion.sol new file mode 100644 index 00000000..40f85ccc --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_payable_storage_array_conversion.sol @@ -0,0 +1,11 @@ +contract C { + address payable[] a; + address[] b; + function f() public view { + address payable[] storage c = a; + address[] storage d = b; + d = c; // TODO: this could be allowed in the future + } +} +// ---- +// TypeError: (172-173): Type address payable[] storage pointer is not implicitly convertible to expected type address[] storage pointer. diff --git a/test/libsolidity/syntaxTests/types/address/address_payable_storage_array_conversion_fail.sol b/test/libsolidity/syntaxTests/types/address/address_payable_storage_array_conversion_fail.sol new file mode 100644 index 00000000..3c3eb859 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_payable_storage_array_conversion_fail.sol @@ -0,0 +1,11 @@ +contract C { + address payable[] a; + address[] b; + function f() public view { + address payable[] storage c = a; + address[] storage d = b; + c = d; + } +} +// ---- +// TypeError: (172-173): Type address[] storage pointer is not implicitly convertible to expected type address payable[] storage pointer. diff --git a/test/libsolidity/syntaxTests/types/address/address_to_contract_implicitly.sol b/test/libsolidity/syntaxTests/types/address/address_to_contract_implicitly.sol new file mode 100644 index 00000000..c9e5ddf6 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_to_contract_implicitly.sol @@ -0,0 +1,7 @@ +contract C { + function f() public view { + C c = address(2); + } +} +// ---- +// TypeError: (46-62): Type address payable is not implicitly convertible to expected type contract C. diff --git a/test/libsolidity/syntaxTests/types/address/address_to_contract_payable_fallback.sol b/test/libsolidity/syntaxTests/types/address/address_to_contract_payable_fallback.sol new file mode 100644 index 00000000..6917444b --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_to_contract_payable_fallback.sol @@ -0,0 +1,8 @@ +contract C { + function f() public pure returns (C c) { + c = C(address(2)); + } + function() external payable { + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/address_to_payable_address.sol b/test/libsolidity/syntaxTests/types/address/address_to_payable_address.sol new file mode 100644 index 00000000..1aab9b51 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_to_payable_address.sol @@ -0,0 +1,10 @@ +contract C { + function f(address a) public pure { + address b; + address payable c = a; + c = b; + } +} +// ---- +// TypeError: (80-101): Type address is not implicitly convertible to expected type address payable. +// TypeError: (115-116): Type address is not implicitly convertible to expected type address payable. diff --git a/test/libsolidity/syntaxTests/types/address/address_tuple_fail.sol b/test/libsolidity/syntaxTests/types/address/address_tuple_fail.sol new file mode 100644 index 00000000..17e9e7c1 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_tuple_fail.sol @@ -0,0 +1,8 @@ +contract C { + function f() public view returns (address payable a, address b) { + (address c, address payable d) = (address(this), address(0)); + (a,b) = (c,d); + } +} +// ---- +// TypeError: (169-174): Type tuple(address,address payable) is not implicitly convertible to expected type tuple(address payable,address). diff --git a/test/libsolidity/syntaxTests/types/address/address_tuple_fine.sol b/test/libsolidity/syntaxTests/types/address/address_tuple_fine.sol new file mode 100644 index 00000000..846de1f4 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/address_tuple_fine.sol @@ -0,0 +1,6 @@ +contract C { + function f() public view returns (address payable a, address b) { + (address c, address payable d) = (address(this), address(0)); + (a,b) = (d,c); + } +}
\ No newline at end of file diff --git a/test/libsolidity/syntaxTests/types/address/contract_no_fallback_to_payable_address.sol b/test/libsolidity/syntaxTests/types/address/contract_no_fallback_to_payable_address.sol new file mode 100644 index 00000000..777bce00 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/contract_no_fallback_to_payable_address.sol @@ -0,0 +1,8 @@ +contract C { + function f() public view { + address payable a = address(this); + a; + } +} +// ---- +// TypeError: (46-79): Type address is not implicitly convertible to expected type address payable. diff --git a/test/libsolidity/syntaxTests/types/address/contract_non_payable_fallback_to_payable_address.sol b/test/libsolidity/syntaxTests/types/address/contract_non_payable_fallback_to_payable_address.sol new file mode 100644 index 00000000..6518eebb --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/contract_non_payable_fallback_to_payable_address.sol @@ -0,0 +1,10 @@ +contract C { + function f() public view { + address payable a = address(this); + a; + } + function() external { + } +} +// ---- +// TypeError: (46-79): Type address is not implicitly convertible to expected type address payable. 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 new file mode 100644 index 00000000..359beeb4 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/contract_payable_fallback_to_payable_address.sol @@ -0,0 +1,9 @@ +contract C { + function f() public view { + address payable a = address(this); + a; + } + function() external payable { + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/types/address/contract_payable_fallback_to_payable_address_implicitly.sol b/test/libsolidity/syntaxTests/types/address/contract_payable_fallback_to_payable_address_implicitly.sol new file mode 100644 index 00000000..4b20b1c6 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/contract_payable_fallback_to_payable_address_implicitly.sol @@ -0,0 +1,10 @@ +contract C { + function f() public view { + address payable a = this; + a; + } + function() external payable { + } +} +// ---- +// TypeError: (46-70): Type contract C is not implicitly convertible to expected type address payable. diff --git a/test/libsolidity/syntaxTests/types/address/literal_to_address.sol b/test/libsolidity/syntaxTests/types/address/literal_to_address.sol new file mode 100644 index 00000000..9d599ea5 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/literal_to_address.sol @@ -0,0 +1,8 @@ +contract C { + function f() public pure { + address a = address(0); + a = address(1); + address b = 0x0123456789012345678901234567890123456789; + b = 0x9876543210987654321098765432109876543210; + } +} diff --git a/test/libsolidity/syntaxTests/types/address/literal_to_payable_address.sol b/test/libsolidity/syntaxTests/types/address/literal_to_payable_address.sol new file mode 100644 index 00000000..97f4d85d --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/literal_to_payable_address.sol @@ -0,0 +1,8 @@ +contract C { + function f() public pure { + address payable a = address(0); + a = address(1); + address payable b = 0x0123456789012345678901234567890123456789; + b = 0x9876543210987654321098765432109876543210; + } +}
\ No newline at end of file diff --git a/test/libsolidity/syntaxTests/types/address/nonpayable_address_to_contract_payable_fallback.sol b/test/libsolidity/syntaxTests/types/address/nonpayable_address_to_contract_payable_fallback.sol new file mode 100644 index 00000000..e13a0897 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/nonpayable_address_to_contract_payable_fallback.sol @@ -0,0 +1,10 @@ +contract C { + function f() public pure returns (C c) { + address a = address(2); + c = C(a); + } + function() external payable { + } +} +// ---- +// TypeError: (92-96): Explicit type conversion not allowed from non-payable "address" to "contract C", which has a payable fallback function. diff --git a/test/libsolidity/syntaxTests/types/address/payable_address_to_address.sol b/test/libsolidity/syntaxTests/types/address/payable_address_to_address.sol new file mode 100644 index 00000000..f5dbf937 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/address/payable_address_to_address.sol @@ -0,0 +1,7 @@ +contract C { + function f(address payable a) public pure { + address payable b; + address c = a; + c = b; + } +}
\ No newline at end of file diff --git a/test/libsolidity/syntaxTests/types/address_to_contract_implicitly.sol b/test/libsolidity/syntaxTests/types/address_to_contract_implicitly.sol deleted file mode 100644 index efab7c27..00000000 --- a/test/libsolidity/syntaxTests/types/address_to_contract_implicitly.sol +++ /dev/null @@ -1,7 +0,0 @@ -contract C { - function f() public view { - C c = address(2); - } -} -// ---- -// TypeError: (46-62): Type address is not implicitly convertible to expected type contract C. |