Skip to content

Allow signed expressions in storage layout specifier#16589

Open
matheusaaguiar wants to merge 2 commits intodevelopfrom
storage_layout_expression_accept_signed_positive_integer
Open

Allow signed expressions in storage layout specifier#16589
matheusaaguiar wants to merge 2 commits intodevelopfrom
storage_layout_expression_accept_signed_positive_integer

Conversation

@matheusaaguiar
Copy link
Copy Markdown
Contributor

Suggested in #16456 (comment)

We intended to reject signed expressions for layout specifier, but since array lengths do accept them, this makes the handling consistent between both.
I guess not a bug then.

Comment thread Changelog.md

Language Features:
* General: Add a builtin that computes the base slot of a storage namespace using the `erc7201` formula from ERC-7201.
* Custom Storage Layout: Allow signed positive expressions.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this up to maintain alphabetical ordering.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, fixed!

uint constant UNSIGNED2 = 2;

contract A layout at SIGNED2 * 1 {}
contract B layout at SIGNED2_NEGATIVE * -1 {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have the opposite covered somewhere, i.e. where a 'complex' expression evaluates to a negative number, e.g. SIGNED2_NEGATIVE * 1? Although int_const_negative.sol would be a better place for such a test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to int_constant_negative.sol.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to add some max values in here, e.g. int constant x = type(int).max, although I assume we already have them around somewhere (likely in the initial implementation of the storage layout specifiers).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, just checked and type(<type>).max is not supported by the constant expression evaluator at the moment :D

@matheusaaguiar matheusaaguiar force-pushed the storage_layout_expression_accept_signed_positive_integer branch from f27bc10 to adee0c8 Compare April 15, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants