From 721cef3885f9b3f29a7eab9fb40313b77975030a Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Sat, 15 Mar 2025 12:09:55 -0300 Subject: [PATCH 1/5] Update and add tests --- .../syntaxTests/storageLayoutSpecifier/abi_decode.sol | 2 +- .../storageLayoutSpecifier/address_constant.sol | 6 ++++++ .../bitwise_negation_after_cast.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/bool_constant.sol | 4 ++++ .../syntaxTests/storageLayoutSpecifier/bytes_constant.sol | 6 ++++++ .../constant_divided_by_its_negation.sol | 2 +- .../storageLayoutSpecifier/constant_divided_by_zero.sol | 2 +- .../constant_from_base_contract.sol | 2 +- .../storageLayoutSpecifier/constant_from_module.sol | 8 ++++++++ .../constant_initialized_from_builtin.sol | 7 +++++++ .../constant_initialized_from_cast.sol | 4 ++++ .../constant_initialized_from_other_constant.sol | 4 ++++ .../constant_initialized_with_literal_expression.sol | 3 +++ .../storageLayoutSpecifier/function_selector.sol | 2 +- .../storageLayoutSpecifier/hex_string_cast.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/int_constant.sol | 4 ++++ .../layout_specification_constant_in_expression.sol | 1 - .../layout_specified_by_interface_id.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/literal_cast.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/precompiles.sol | 4 ++-- .../storageLayoutSpecifier/ternary_operator.sol | 4 ++-- .../syntaxTests/storageLayoutSpecifier/type_uint_max.sol | 2 +- .../user_defined_value_type_unwrap.sol | 2 +- .../storageLayoutSpecifier/value_from_array_literal.sol | 4 ++-- .../storageLayoutSpecifier/value_from_bytes.sol | 2 +- 25 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/address_constant.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/bool_constant.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/bytes_constant.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_from_module.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_builtin.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_cast.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_other_constant.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_with_literal_expression.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant.sol diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/abi_decode.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/abi_decode.sol index 920e8d252c2b..767462ea9c70 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/abi_decode.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/abi_decode.sol @@ -1,3 +1,3 @@ contract C layout at abi.decode(abi.encode(42), (uint)) {} // ---- -// TypeError 6396: (21-55): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (21-55): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/address_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/address_constant.sol new file mode 100644 index 000000000000..24a862e50e1a --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/address_constant.sol @@ -0,0 +1,6 @@ +address constant x = 0xdCad3a6d3569DF655070DEd06cb7A1b2Ccd1D3AF; +contract C layout at x { + +} +// ---- +// TypeError 6396: (86-87): The base slot of the storage layout must evaluate to a rational number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/bitwise_negation_after_cast.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bitwise_negation_after_cast.sol index 6ccb2ff7a1c8..091cc1685d25 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/bitwise_negation_after_cast.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bitwise_negation_after_cast.sol @@ -1,3 +1,3 @@ contract C layout at ~uint(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) {} // ---- -// TypeError 6396: (21-94): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (21-94): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/bool_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bool_constant.sol new file mode 100644 index 000000000000..847bd6ba7af2 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bool_constant.sol @@ -0,0 +1,4 @@ +bool constant x = false; +contract C layout at x {} +// ---- +// TypeError 6396: (46-47): The base slot of the storage layout must evaluate to a rational number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/bytes_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bytes_constant.sol new file mode 100644 index 000000000000..eb4ef6628453 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bytes_constant.sol @@ -0,0 +1,6 @@ +bytes32 constant x = "ABC"; +contract A layout at x {} +contract C layout at x[1] {} +// ---- +// TypeError 6396: (49-50): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (75-79): The base slot of the storage layout must evaluate to a rational number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_divided_by_its_negation.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_divided_by_its_negation.sol index b9cdd9dfaae2..9f8acbeb6a36 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_divided_by_its_negation.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_divided_by_its_negation.sol @@ -1,4 +1,4 @@ uint constant N = 100; contract C layout at N / ~N {} // ---- -// TypeError 6396: (44-50): The base slot of the storage layout must evaluate to a rational number. +// TypeError 3667: (48-50): Arithmetic error when computing constant value. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_divided_by_zero.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_divided_by_zero.sol index bb97172d996c..47a43ac94974 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_divided_by_zero.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_divided_by_zero.sol @@ -1,4 +1,4 @@ uint constant N = 100; contract C layout at N / 0 {} // ---- -// TypeError 6396: (44-49): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (44-49): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_from_base_contract.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_from_base_contract.sol index e06deeaaf2dc..8f6e5c0bfd12 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_from_base_contract.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_from_base_contract.sol @@ -4,4 +4,4 @@ contract A { contract C is A layout at A.x { } // ---- -// TypeError 6396: (68-71): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (68-71): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_from_module.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_from_module.sol new file mode 100644 index 000000000000..688df5644cac --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_from_module.sol @@ -0,0 +1,8 @@ +==== Source: A ==== +uint constant x = 77; + +==== Source: B ==== +import "A" as M; +contract C layout at M.x{ } +// ---- +// TypeError 1505: (B:38-41): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_builtin.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_builtin.sol new file mode 100644 index 000000000000..2d5a1abb92c5 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_builtin.sol @@ -0,0 +1,7 @@ +uint constant x = addmod(10, 2, 8); +uint constant y = mulmod(10, 2, 8); +contract C layout at x {} +contract D layout at y {} +// ---- +// TypeError 1505: (93-94): The base slot expression cannot be evaluated during compilation. +// TypeError 1505: (119-120): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_cast.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_cast.sol new file mode 100644 index 000000000000..4b50d88c7ad9 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_cast.sol @@ -0,0 +1,4 @@ +uint constant x = uint(42); +contract C layout at x {} +// ---- +// TypeError 1505: (49-50): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_other_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_other_constant.sol new file mode 100644 index 000000000000..1b135b32b471 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_from_other_constant.sol @@ -0,0 +1,4 @@ +uint constant x = 42; +uint constant y = x * 2; +contract C layout at y {} +// ---- diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_with_literal_expression.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_with_literal_expression.sol new file mode 100644 index 000000000000..1a06c0198f50 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/constant_initialized_with_literal_expression.sol @@ -0,0 +1,3 @@ +uint constant x = ((2**5 + 2**5) * (2 ** 10 + 1 << 1)) % 2**256 - 1; +contract C layout at x {} +// ---- diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/function_selector.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/function_selector.sol index 98c7b6057abe..29ff3ab6617d 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/function_selector.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/function_selector.sol @@ -3,4 +3,4 @@ contract A { } contract C is A layout at uint32(this.f.selector) {} // ---- -// TypeError 6396: (68-91): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (68-91): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_string_cast.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_string_cast.sol index a803d005f7dd..f5da8f056eca 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_string_cast.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_string_cast.sol @@ -1,3 +1,3 @@ contract at layout at uint40(bytes5(hex"0011223344")) { } // ---- -// TypeError 6396: (22-53): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (22-53): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant.sol new file mode 100644 index 000000000000..055dd0321c53 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant.sol @@ -0,0 +1,4 @@ +int constant x = -42; +contract C layout at x {} +// ---- +// TypeError 1481: (43-44): The base slot expression must have an unsigned integer type. 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 8e6d37ad6e1f..2f0891e868d1 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_constant_in_expression.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_constant_in_expression.sol @@ -1,4 +1,3 @@ uint constant X = 42; contract C layout at 0xffff * (50 - X) { } // ---- -// TypeError 6396: (43-60): The base slot of the storage layout must evaluate to a rational number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_interface_id.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_interface_id.sol index 12304ba8a0bd..2b61547b4acb 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_interface_id.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_interface_id.sol @@ -2,4 +2,4 @@ interface I {} contract C layout at uint(bytes32(type(I).interfaceId)) { } // ---- -// TypeError 6396: (37-71): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (37-71): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/literal_cast.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/literal_cast.sol index 0f682d779b0b..3495ff897f5c 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/literal_cast.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/literal_cast.sol @@ -1,3 +1,3 @@ contract at layout at uint(42) { } // ---- -// TypeError 6396: (22-30): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (22-30): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/precompiles.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/precompiles.sol index c87a98eaa919..392b653c5d92 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/precompiles.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/precompiles.sol @@ -1,5 +1,5 @@ contract A layout at addmod(1, 2, 3) {} contract B layout at mulmod(3, 2, 1) {} // ---- -// TypeError 6396: (21-36): The base slot of the storage layout must evaluate to a rational number. -// TypeError 6396: (61-76): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (21-36): The base slot expression cannot be evaluated during compilation. +// TypeError 1505: (61-76): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/ternary_operator.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/ternary_operator.sol index f426104cc2cb..033488fb1038 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/ternary_operator.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/ternary_operator.sol @@ -1,5 +1,5 @@ contract A layout at true ? 42 : 94 {} contract B layout at 255 + (true ? 1 : 0) {} // ---- -// TypeError 6396: (21-35): The base slot of the storage layout must evaluate to a rational number. -// TypeError 6396: (60-80): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (21-35): The base slot expression cannot be evaluated during compilation. +// TypeError 1505: (60-80): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/type_uint_max.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/type_uint_max.sol index dd8ee6f9cc27..73658d8af555 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/type_uint_max.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/type_uint_max.sol @@ -1,3 +1,3 @@ contract at layout at type(uint).max { } // ---- -// TypeError 6396: (22-36): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (22-36): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type_unwrap.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type_unwrap.sol index b45ee88dd98d..9b1afb3ee537 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type_unwrap.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type_unwrap.sol @@ -2,4 +2,4 @@ type MyUint is uint128; MyUint constant x = MyUint.wrap(42); contract C layout at MyUint.unwrap(x) {} // ---- -// TypeError 6396: (82-98): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (82-98): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/value_from_array_literal.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/value_from_array_literal.sol index bb56de728944..27dbfb8a50b7 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/value_from_array_literal.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/value_from_array_literal.sol @@ -1,5 +1,5 @@ contract A layout at [1, 2, 3][0] {} contract B layout at 255 + [1, 2, 3][0] {} // ---- -// TypeError 6396: (21-33): The base slot of the storage layout must evaluate to a rational number. -// TypeError 6396: (58-76): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (21-33): The base slot expression cannot be evaluated during compilation. +// TypeError 1505: (58-76): The base slot expression cannot be evaluated during compilation. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/value_from_bytes.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/value_from_bytes.sol index 1f08fa0ec9ee..270f132d2ba1 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/value_from_bytes.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/value_from_bytes.sol @@ -1,4 +1,4 @@ bytes32 constant b = "Solidity"; contract C layout at uint8(b[1]) {} // ---- -// TypeError 6396: (54-65): The base slot of the storage layout must evaluate to a rational number. +// TypeError 1505: (54-65): The base slot expression cannot be evaluated during compilation. From 54c4b91b9c3e8271e3200765ffe0b624c81972ed Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Sat, 15 Mar 2025 12:10:44 -0300 Subject: [PATCH 2/5] Allow constants in custom storage layout expression --- .../analysis/PostTypeContractLevelChecker.cpp | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/libsolidity/analysis/PostTypeContractLevelChecker.cpp b/libsolidity/analysis/PostTypeContractLevelChecker.cpp index c7b7b0961622..b3d69aab51ce 100644 --- a/libsolidity/analysis/PostTypeContractLevelChecker.cpp +++ b/libsolidity/analysis/PostTypeContractLevelChecker.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -101,8 +102,10 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio } auto const* baseSlotExpressionType = type(baseSlotExpression); - auto const* rationalType = dynamic_cast(baseSlotExpressionType); - if (!rationalType) + if ( + !dynamic_cast(baseSlotExpressionType) && + !dynamic_cast(baseSlotExpressionType) + ) { m_errorReporter.typeError( 6396_error, @@ -112,18 +115,48 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio return; } - if (rationalType->isFractional()) + rational baseSlotRationalValue; + if (auto const integerType = dynamic_cast(baseSlotExpressionType)) { - m_errorReporter.typeError( - 1763_error, - baseSlotExpression.location(), - "The base slot of the storage layout must evaluate to an integer." - ); - return; + if (integerType->isSigned()) + { + m_errorReporter.typeError( + 1481_error, + baseSlotExpression.location(), + "The base slot expression must have an unsigned integer type." + ); + return; + } + std::optional typedRational = ConstantEvaluator::evaluate(m_errorReporter, baseSlotExpression); + if (!typedRational) + { + m_errorReporter.typeError( + 1505_error, + baseSlotExpression.location(), + "The base slot expression cannot be evaluated during compilation." + ); + return; + } + baseSlotRationalValue = typedRational->value; + } + else + { + auto const* rationalType = dynamic_cast(baseSlotExpressionType); + solAssert(rationalType); + if (rationalType->isFractional()) + { + m_errorReporter.typeError( + 1763_error, + baseSlotExpression.location(), + "The base slot of the storage layout must evaluate to an integer." + ); + return; + } + baseSlotRationalValue = rationalType->value(); } - solAssert(rationalType->value().denominator() == 1); - bigint baseSlot = rationalType->value().numerator(); + solAssert(baseSlotRationalValue.denominator() == 1); + bigint baseSlot = baseSlotRationalValue.numerator(); if (!(0 <= baseSlot && baseSlot <= std::numeric_limits::max())) { m_errorReporter.typeError( From 484148dc9075260a79922e6a1614beab6925d7fd Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Wed, 26 Mar 2025 23:31:58 -0300 Subject: [PATCH 3/5] Change error message --- libsolidity/analysis/PostTypeContractLevelChecker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/analysis/PostTypeContractLevelChecker.cpp b/libsolidity/analysis/PostTypeContractLevelChecker.cpp index b3d69aab51ce..8961ff97e617 100644 --- a/libsolidity/analysis/PostTypeContractLevelChecker.cpp +++ b/libsolidity/analysis/PostTypeContractLevelChecker.cpp @@ -110,7 +110,7 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio m_errorReporter.typeError( 6396_error, baseSlotExpression.location(), - "The base slot of the storage layout must evaluate to a rational number." + "The base slot of the storage layout must evaluate to a rational integer number." ); return; } From 6b8a352bdde7c0dc134b28a8b3161f29a573f846 Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Wed, 26 Mar 2025 23:32:21 -0300 Subject: [PATCH 4/5] Update tests after changing error message --- .../syntaxTests/storageLayoutSpecifier/address.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/address_constant.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/array_literal.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/bool_constant.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/boolean.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/bytes_constant.sol | 4 ++-- test/libsolidity/syntaxTests/storageLayoutSpecifier/enum.sol | 2 +- .../function_defined_in_other_contract.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/hex_address.sol | 2 +- .../syntaxTests/storageLayoutSpecifier/hex_string.sol | 2 +- .../storageLayoutSpecifier/layout_specification_bytes.sol | 2 +- .../storageLayoutSpecifier/layout_specified_by_module.sol | 2 +- .../layout_specified_by_other_contract.sol | 2 +- .../storageLayoutSpecifier/layout_specified_by_type.sol | 2 +- .../libsolidity/syntaxTests/storageLayoutSpecifier/string.sol | 2 +- test/libsolidity/syntaxTests/storageLayoutSpecifier/tuple.sol | 2 +- .../storageLayoutSpecifier/user_defined_value_type.sol | 2 +- .../storageLayoutSpecifier/user_defined_value_type_wrap.sol | 2 +- 18 files changed, 19 insertions(+), 19 deletions(-) diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/address.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/address.sol index fded26fadd0d..2e4eb1d8fae1 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/address.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/address.sol @@ -1,3 +1,3 @@ contract C layout at address(0x1234) {} // ---- -// TypeError 6396: (21-36): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (21-36): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/address_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/address_constant.sol index 24a862e50e1a..ee5c4e72415d 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/address_constant.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/address_constant.sol @@ -3,4 +3,4 @@ contract C layout at x { } // ---- -// TypeError 6396: (86-87): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (86-87): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/array_literal.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/array_literal.sol index af6b9424f607..6dbe95714899 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/array_literal.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/array_literal.sol @@ -1,3 +1,3 @@ contract C layout at [1, 2, 3] {} // ---- -// TypeError 6396: (21-30): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (21-30): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/bool_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bool_constant.sol index 847bd6ba7af2..d0b01223ac10 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/bool_constant.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bool_constant.sol @@ -1,4 +1,4 @@ bool constant x = false; contract C layout at x {} // ---- -// TypeError 6396: (46-47): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (46-47): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/boolean.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/boolean.sol index 083977c7ae15..f3076827e00c 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/boolean.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/boolean.sol @@ -1,3 +1,3 @@ contract C layout at true {} // ---- -// TypeError 6396: (21-25): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (21-25): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/bytes_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bytes_constant.sol index eb4ef6628453..38fc805553e2 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/bytes_constant.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/bytes_constant.sol @@ -2,5 +2,5 @@ bytes32 constant x = "ABC"; contract A layout at x {} contract C layout at x[1] {} // ---- -// TypeError 6396: (49-50): The base slot of the storage layout must evaluate to a rational number. -// TypeError 6396: (75-79): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (49-50): The base slot of the storage layout must evaluate to a rational integer number. +// TypeError 6396: (75-79): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/enum.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/enum.sol index 9a264247c8d0..b29fe11c415f 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/enum.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/enum.sol @@ -2,4 +2,4 @@ enum Color {Red, Green, Blue} contract C layout at Color.Red {} // ---- -// TypeError 6396: (52-61): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (52-61): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/function_defined_in_other_contract.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/function_defined_in_other_contract.sol index 68b2e2460471..cfebf29cfbb1 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/function_defined_in_other_contract.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/function_defined_in_other_contract.sol @@ -4,4 +4,4 @@ contract A { contract C layout at A.f { } // ---- -// TypeError 6396: (71-74): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (71-74): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_address.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_address.sol index 9e63740d89f3..14b14bbd3849 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_address.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_address.sol @@ -1,3 +1,3 @@ contract C layout at 0xdCad3a6d3569DF655070DEd06cb7A1b2Ccd1D3AF {} // ---- -// TypeError 6396: (21-63): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (21-63): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_string.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_string.sol index 194f0df0ea9a..95a34001e873 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_string.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/hex_string.sol @@ -1,3 +1,3 @@ contract C layout at hex"616263" {} // ---- -// TypeError 6396: (21-32): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (21-32): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_bytes.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_bytes.sol index 6f9b39703afa..1af734b7bffe 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_bytes.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specification_bytes.sol @@ -1,4 +1,4 @@ bytes32 constant b = "bytes"; contract A layout at b[1] {} // ---- -// TypeError 6396: (51-55): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (51-55): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_module.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_module.sol index ee480730434c..7b00489e19f5 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_module.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_module.sol @@ -6,4 +6,4 @@ import "A" as MyModule; contract C layout at MyModule {} // ---- -// TypeError 6396: (B:46-54): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (B:46-54): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_other_contract.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_other_contract.sol index 035e43d24ae4..0863e8ccba59 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_other_contract.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_other_contract.sol @@ -1,4 +1,4 @@ contract A {} contract C layout at A(address(0x1234)) {} // ---- -// TypeError 6396: (35-53): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (35-53): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_type.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_type.sol index 4d48e410f881..d9959d7f2bac 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_type.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/layout_specified_by_type.sol @@ -1,3 +1,3 @@ contract A layout at uint {} // ---- -// TypeError 6396: (21-25): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (21-25): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/string.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/string.sol index 3b8292fe8cbd..0b4cf7b88e6b 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/string.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/string.sol @@ -1,3 +1,3 @@ contract C layout at "MyLayoutBase" {} // ---- -// TypeError 6396: (21-35): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (21-35): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/tuple.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/tuple.sol index eb4693e488d1..adf0156b6b74 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/tuple.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/tuple.sol @@ -1,3 +1,3 @@ contract C layout at (1, 2, 3) {} // ---- -// TypeError 6396: (21-30): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (21-30): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type.sol index 98036416880a..7b9464011bb5 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type.sol @@ -2,4 +2,4 @@ type MyUint is uint128; MyUint constant x = MyUint.wrap(42); contract C layout at x {} // ---- -// TypeError 6396: (82-83): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (82-83): The base slot of the storage layout must evaluate to a rational integer number. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type_wrap.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type_wrap.sol index 172fb58ab12c..87ce16309a27 100644 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type_wrap.sol +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/user_defined_value_type_wrap.sol @@ -1,4 +1,4 @@ type MyUint is uint128; contract C layout at MyUint.wrap(42) {} // ---- -// TypeError 6396: (45-60): The base slot of the storage layout must evaluate to a rational number. +// TypeError 6396: (45-60): The base slot of the storage layout must evaluate to a rational integer number. From d1dbd2e7d653db74a1d5e0a54cd2274bf4cec577 Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Tue, 22 Apr 2025 16:21:43 -0300 Subject: [PATCH 5/5] fixup! Update and add tests --- .../syntaxTests/storageLayoutSpecifier/immutables.sol | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/immutables.sol diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/immutables.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/immutables.sol new file mode 100644 index 000000000000..34a8121148b7 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/immutables.sol @@ -0,0 +1,10 @@ +contract A { + address immutable a = 0x0000000000000000000000000000000000000001; + uint immutable x = 1; +} + +contract B is A layout at A.a { } +contract C is A layout at A.x { } +// ---- +// TypeError 1139: (138-141): The base slot of the storage layout must be a compile-time constant expression. +// TypeError 1139: (172-175): The base slot of the storage layout must be a compile-time constant expression.