diff --git a/test/cmdlineTests/storage_base_location_defined_ancestor/in.sol b/test/cmdlineTests/storage_base_location_defined_ancestor/in.sol new file mode 100644 index 000000000000..b73bff38d6a7 --- /dev/null +++ b/test/cmdlineTests/storage_base_location_defined_ancestor/in.sol @@ -0,0 +1,10 @@ +//SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; +contract A layout at 0x1234 { +} + +contract B is A { +} + +contract C layout at 0x1234 is B { +} \ No newline at end of file diff --git a/test/cmdlineTests/storage_base_location_defined_ancestor/input.json b/test/cmdlineTests/storage_base_location_defined_ancestor/input.json new file mode 100644 index 000000000000..fd7646d04d6c --- /dev/null +++ b/test/cmdlineTests/storage_base_location_defined_ancestor/input.json @@ -0,0 +1,11 @@ +{ + "language": "Solidity", + "sources": { + "fileA": {"urls": ["storage_base_location_defined_ancestor/in.sol"]} + }, + "settings": { + "outputSelection": { + "fileA": { "A": ["*"] } + } + } +} diff --git a/test/cmdlineTests/storage_base_location_defined_ancestor/output.json b/test/cmdlineTests/storage_base_location_defined_ancestor/output.json new file mode 100644 index 000000000000..d8443d457a6b --- /dev/null +++ b/test/cmdlineTests/storage_base_location_defined_ancestor/output.json @@ -0,0 +1,69 @@ +{ + "errors": [ + { + "component": "general", + "errorCode": "8894", + "formattedMessage": "TypeError: Storage base location can only be specified in the most derived contract. + --> fileA:6:1: + | +6 | contract B is A { + | ^ (Relevant source part starts here and spans across multiple lines). +Note: Storage base location was already specified here. + --> fileA:3:12: + | +3 | contract A layout at 0x1234 { + | ^^^^^^^^^^^^^^^^ + +", + "message": "Storage base location can only be specified in the most derived contract.", + "secondarySourceLocations": [ + { + "end": 85, + "file": "fileA", + "message": "Storage base location was already specified here.", + "start": 69 + } + ], + "severity": "error", + "sourceLocation": { + "end": 110, + "file": "fileA", + "start": 91 + }, + "type": "TypeError" + }, + { + "component": "general", + "errorCode": "8894", + "formattedMessage": "TypeError: Storage base location can only be specified in the most derived contract. + --> fileA:9:1: + | +9 | contract C layout at 0x1234 is B { + | ^ (Relevant source part starts here and spans across multiple lines). +Note: Storage base location was already specified here. + --> fileA:3:12: + | +3 | contract A layout at 0x1234 { + | ^^^^^^^^^^^^^^^^ + +", + "message": "Storage base location can only be specified in the most derived contract.", + "secondarySourceLocations": [ + { + "end": 85, + "file": "fileA", + "message": "Storage base location was already specified here.", + "start": 69 + } + ], + "severity": "error", + "sourceLocation": { + "end": 148, + "file": "fileA", + "start": 112 + }, + "type": "TypeError" + } + ], + "sources": {} +} diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/abstract_contract.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/abstract_contract.sol new file mode 100644 index 000000000000..af5f195a3f55 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/abstract_contract.sol @@ -0,0 +1,4 @@ +abstract contract C layout at 0x123 { +} +// ---- +// TypeError 7587: (20-35): Storage layout cannot be specified for abstract contracts or libraries diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_already_specified_in_ancestor_contract_.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_already_specified_in_ancestor_contract_.sol new file mode 100644 index 000000000000..d525d92066a0 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_already_specified_in_ancestor_contract_.sol @@ -0,0 +1,8 @@ +contract A layout at 0x1234 {} + +contract B is A {} + +contract C is B layout at 0xABCD {} +// ---- +// TypeError 8894: (32-50): Storage layout can only be specified in the most derived contract. +// TypeError 8894: (52-87): Storage layout can only be specified in the most derived contract. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_bitwise_negation_literal.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_bitwise_negation_literal.sol new file mode 100644 index 000000000000..6d88339c9319 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_bitwise_negation_literal.sol @@ -0,0 +1,3 @@ +contract C layout at ~0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE {} +// ---- +// TypeError 1763: (21-88): Storage layout cannot be specified by a number exceeding the range of type uint256. Current type is int_const -115...(71 digits omitted)...9935 Cannot implicitly convert signed literal to unsigned type. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_fractional_number.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_fractional_number.sol new file mode 100644 index 000000000000..ea61db3d2481 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_fractional_number.sol @@ -0,0 +1,3 @@ +contract A layout at 3/2 {} +// ---- +// TypeError 1763: (21-24): Storage layout cannot be specified by a fractional number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_not_specified_in_most_derived_contract_copy.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_not_specified_in_most_derived_contract_copy.sol new file mode 100644 index 000000000000..31610eca0565 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_not_specified_in_most_derived_contract_copy.sol @@ -0,0 +1,8 @@ +contract A layout at 0x1234 {} + +contract B is A {} + +contract C is B {} +// ---- +// TypeError 8894: (32-50): Storage layout can only be specified in the most derived contract. +// TypeError 8894: (52-70): Storage layout can only be specified in the most derived contract. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_binary_expression.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_binary_expression.sol index 2623fcaa7d83..fffea1458e87 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_binary_expression.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_binary_expression.sol @@ -1,4 +1,2 @@ contract C layout at 0xffff * (0x123 + 0xABC) { } -// ==== -// stopAfter: parsing // ---- diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_bytes.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_bytes.sol new file mode 100644 index 000000000000..4e92b49d184e --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_bytes.sol @@ -0,0 +1,4 @@ +bytes32 constant b = "bytes"; +contract A layout at b[1] {} +// ---- +// TypeError 1763: (51-55): Storage layout cannot be specified by a number exceeding the range of type uint256. Current type is bytes1 diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_constant_in_expression.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_constant_in_expression.sol index 3b034da9ef9d..acb54048b7a5 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_constant_in_expression.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_constant_in_expression.sol @@ -1,5 +1,4 @@ uint constant X = 42; contract C layout at 0xffff * (50 - X) { } -// ==== -// stopAfter: parsing // ---- +// TypeError 6396: (43-60): The storage layout can only be specified by number literals. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_function_erc7201.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_function_erc7201.sol index cd905d4974d3..2d8c2f4f25f0 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_function_erc7201.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_function_erc7201.sol @@ -5,6 +5,6 @@ function erc7201(bytes memory id) pure returns (uint256) { ); } contract C layout at erc7201("C") { } -// ==== -// stopAfter: parsing // ---- +// TypeError 1139: (212-224): The storage layout must be specified by an expression that can be evaluated at compilation time. +// TypeError 6396: (212-224): The storage layout can only be specified by number literals. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_max_value.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_max_value.sol new file mode 100644 index 000000000000..793b5b2689cf --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_max_value.sol @@ -0,0 +1,2 @@ +contract C layout at 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF {} +// ---- diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_overflow_value.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_overflow_value.sol new file mode 100644 index 000000000000..21528d169a6f --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_overflow_value.sol @@ -0,0 +1,3 @@ +contract C layout at 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF + 1 {} +// ---- +// TypeError 1763: (21-91): Storage layout cannot be specified by a number exceeding the range of type uint256. Current type is int_const 1157...(70 digits omitted)...9936 Literal is too large to fit in uint256. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_underflow_value.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_underflow_value.sol new file mode 100644 index 000000000000..921911adc428 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_underflow_value.sol @@ -0,0 +1,3 @@ +contract A layout at 0 - 1 {} +// ---- +// TypeError 1763: (21-26): Storage layout cannot be specified by a number exceeding the range of type uint256. Current type is int_const -1 Cannot implicitly convert signed literal to unsigned type. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_expression_not_pure.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_expression_not_pure.sol new file mode 100644 index 000000000000..815416c0ef83 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_expression_not_pure.sol @@ -0,0 +1,5 @@ +function f(uint x) returns (uint) { return x + 1; } +contract A layout at f(2) {} +// ---- +// TypeError 1139: (73-77): The storage layout must be specified by an expression that can be evaluated at compilation time. +// TypeError 6396: (73-77): The storage layout can only be specified by number literals. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_with_inheritance.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_with_inheritance.sol index 13e094631c23..a5db31ce926c 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_with_inheritance.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_with_inheritance.sol @@ -1,5 +1,8 @@ contract A { } contract B { } +contract Z { } contract C is A, B layout at 0x1234 { } -contract D layout at 0xABCD is A, B { } +contract D layout at 0xABCD is Z { } // ---- +// TypeError 2031: (70-109): Conflicting storage layout specifications:Storage layout for base contract 'A' was also specified by another contract which derives from it. +// TypeError 2031: (70-109): Conflicting storage layout specifications:Storage layout for base contract 'B' was also specified by another contract which derives from it. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/library.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/library.sol new file mode 100644 index 000000000000..3b96d068d2c8 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/library.sol @@ -0,0 +1,5 @@ +library L layout at 0x123 { + function f() public pure { } +} +// ---- +// TypeError 7587: (10-25): Storage layout cannot be specified for abstract contracts or libraries diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/same_ancestor_two_contracts.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/same_ancestor_two_contracts.sol new file mode 100644 index 000000000000..16e75310e2b6 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/same_ancestor_two_contracts.sol @@ -0,0 +1,5 @@ +contract A {} +contract B is A layout at 64 {} +contract C is A layout at 42 {} +// ---- +// TypeError 2031: (46-77): Conflicting storage layout specifications:Storage layout for base contract 'A' was also specified by another contract which derives from it. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/simple_layout.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/simple_layout.sol index 2d589e2a93a2..024f5a95f941 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/simple_layout.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/simple_layout.sol @@ -1,4 +1,4 @@ contract A layout at 0x1234 {} contract B layout at 1024 {} -contract C layout at "C" {} +contract C layout at 0 {} // ----