Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Converting Array Literals to Dynamically Sized Memory Arrays #15580

Open
kaihiroi opened this issue Nov 21, 2024 · 0 comments
Open
Labels

Comments

@kaihiroi
Copy link

Abstract

Solidity currently doesn't allow converting array literals to dynamically sized memory arrays. This restriction makes initializing dynamic arrays with literals more complex and less intuitive. According to the v0.8.28 documentation, this restriction is planned for removal. I would like to know if there are plans to implement this change.

Motivation

Developers need to write extra code to initialize dynamic arrays, which can lead to longer and harder-to-read code.

Current:

uint[] memory _uintArray = new uint[](3);
_uintArray[0] = 1;
_uintArray[1] = 3;
_uintArray[2] = 4;

someFunctionWithMemoryArrayParam({
    uintArray: _uintArray    
});

Proposed:

someFunctionWithMemoryArrayParam({
    uintArray: [uint(1), 3, 4]
});

Specification

Modify the Solidity compiler to allow the assignment of array literals directly to dynamically sized memory arrays, enabling more intuitive and concise array initialization.

Backwards Compatibility

This change is backward compatible as it only introduces new syntax, ensuring that existing codebases remain unaffected and current methods for initializing dynamic arrays continue to function as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant