From 65a3ac2bdf5fe7ab869e42da40cd55b9d4c84311 Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Thu, 9 Apr 2026 23:11:15 -0300 Subject: [PATCH 1/2] Add and update tests --- .../storageLayoutSpecifier/int_constant.sol | 7 ------- .../int_constant_negative.sol | 13 +++++++++++++ .../int_constant_positive.sol | 5 +++++ .../storageLayoutSpecifier/signed_expressions.sol | 11 +++++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) delete mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant_negative.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant_positive.sol create mode 100644 test/libsolidity/syntaxTests/storageLayoutSpecifier/signed_expressions.sol diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant.sol deleted file mode 100644 index 1299f1347d88..000000000000 --- a/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant.sol +++ /dev/null @@ -1,7 +0,0 @@ -int constant x = -42; -int constant y = 64; -contract C layout at x {} -contract D layout at y {} -// ---- -// TypeError 6753: (64-65): The base slot of the storage layout evaluates to -42, which is outside the range of type uint256. -// TypeError 1481: (90-91): Base slot expression of type 'int256' is not convertible to uint256. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant_negative.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant_negative.sol new file mode 100644 index 000000000000..db78deadb4a6 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant_negative.sol @@ -0,0 +1,13 @@ +int constant INT256 = -42; +int8 constant INT8 = -64; +int constant EXPRESSION = INT256 * 2; +int constant COMPLEX = EXPRESSION * -2 + EXPRESSION * 4; +contract A layout at INT256 {} +contract B layout at INT8 {} +contract C layout at EXPRESSION {} +contract D layout at COMPLEX {} +// ---- +// TypeError 6753: (169-175): The base slot of the storage layout evaluates to -42, which is outside the range of type uint256. +// TypeError 6753: (200-204): The base slot of the storage layout evaluates to -64, which is outside the range of type uint256. +// TypeError 6753: (229-239): The base slot of the storage layout evaluates to -84, which is outside the range of type uint256. +// TypeError 6753: (264-271): The base slot of the storage layout evaluates to -168, which is outside the range of type uint256. diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant_positive.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant_positive.sol new file mode 100644 index 000000000000..5e8b293d259a --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/int_constant_positive.sol @@ -0,0 +1,5 @@ +int constant x = 42; +int16 constant y = 64; +contract C layout at x {} +contract D layout at y {} +// ---- diff --git a/test/libsolidity/syntaxTests/storageLayoutSpecifier/signed_expressions.sol b/test/libsolidity/syntaxTests/storageLayoutSpecifier/signed_expressions.sol new file mode 100644 index 000000000000..0659bb732756 --- /dev/null +++ b/test/libsolidity/syntaxTests/storageLayoutSpecifier/signed_expressions.sol @@ -0,0 +1,11 @@ +int constant SIGNED2 = 2; +int constant SIGNED2_NEGATIVE = -2; +uint constant UNSIGNED2 = 2; + +contract A layout at SIGNED2 * 1 {} +contract B layout at SIGNED2_NEGATIVE * -1 {} +contract C layout at SIGNED2_NEGATIVE * SIGNED2_NEGATIVE {} +contract D layout at 2 * -1 * -1 {} +contract E layout at 2 * SIGNED2 {} +contract F layout at 2 * -1 * SIGNED2_NEGATIVE {} +// ---- From adee0c881046bd334dcf7d5e8f3bcb9e0c0eaea8 Mon Sep 17 00:00:00 2001 From: Matheus Aguiar Date: Thu, 9 Apr 2026 23:11:50 -0300 Subject: [PATCH 2/2] Make storage layout specifier accept signed positive expressions --- Changelog.md | 1 + .../analysis/PostTypeContractLevelChecker.cpp | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/Changelog.md b/Changelog.md index adf89b3ac8f2..269e3a80c94d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ ### 0.8.35 (unreleased) Language Features: +* Custom Storage Layout: Allow signed positive expressions. * General: Add a builtin that computes the base slot of a storage namespace using the `erc7201` formula from ERC-7201. Compiler Features: diff --git a/libsolidity/analysis/PostTypeContractLevelChecker.cpp b/libsolidity/analysis/PostTypeContractLevelChecker.cpp index be5d008a6161..bec4157a1da3 100644 --- a/libsolidity/analysis/PostTypeContractLevelChecker.cpp +++ b/libsolidity/analysis/PostTypeContractLevelChecker.cpp @@ -181,18 +181,6 @@ void PostTypeContractLevelChecker::checkStorageLayoutSpecifier(ContractDefinitio return; } - if (!baseSlotExpressionType->isImplicitlyConvertibleTo(*TypeProvider::uint256())) - { - m_errorReporter.typeError( - 1481_error, - baseSlotExpression.location(), - fmt::format( - "Base slot expression of type '{}' is not convertible to uint256.", - baseSlotExpressionType->humanReadableName() - ) - ); - return; - } storageLayoutSpecifier->annotation().baseSlot = u256(baseSlot); bigint size = contractStorageSizeUpperBound(_contract, VariableDeclaration::Location::Unspecified);