Skip to content

fix(sol-macro): derive Default for dynamic arrays of non-Default elements#1129

Open
satyakwok wants to merge 1 commit into
alloy-rs:mainfrom
satyakwok:fix/default-dynamic-array-non-default-elem
Open

fix(sol-macro): derive Default for dynamic arrays of non-Default elements#1129
satyakwok wants to merge 1 commit into
alloy-rs:mainfrom
satyakwok:fix/default-dynamic-array-non-default-elem

Conversation

@satyakwok

Copy link
Copy Markdown
Contributor

A dynamic Solidity array maps to Vec<T>, whose Default impl holds for any T. can_derive_default still required the element type to be Default for dynamic arrays, so a struct/error with a field like MyEnum[] lost its Default derive under #[sol(all_derives)] even though Vec<MyEnum>: Default.

This mirrors how the field's Rust type is generated (expand_rust_type_to): Some(size)[T; N], NoneVec<T>. Only fixed-size arrays need T: Default (and N <= 32); dynamic arrays are always Default.

Added a regression test (test_default_dynamic_array_of_non_default_elem).

…ents

A dynamic Solidity array maps to Vec<T>, whose Default impl holds for any T.
can_derive_default still required the element type to be Default for dynamic
arrays, so a struct/error with a field like MyEnum[] lost its Default derive
under #[sol(all_derives)] even though Vec<MyEnum>: Default.

Only require the element to be Default (and length <= 32) for fixed-size arrays
([T; N]); dynamic arrays are always Default.
@satyakwok satyakwok force-pushed the fix/default-dynamic-array-non-default-elem branch from afa7bd4 to 066b214 Compare June 14, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant