FuelLabs/sway · error

Arrays in storage have not been implemented yet.

Error message

Arrays in storage have not been implemented yet.

What it means

During storage initialization, sway-core computes the initial StorageSlot values for each storage field from its declared constant. Scalars, b256 and (de)serializable structs/unions/string arrays are handled, but ConstantValue::Array for an array-typed field hits an explicit unimplemented! panic: constant arrays in storage are simply not implemented in this version.

Source

Thrown at sway-core/src/ir_generation/storage.rs:226

                        .try_into()
                        .unwrap(),
                ),
            )]
        }
        ConstantValue::U256(b) if ty.is_uint_of(context, 256) => {
            vec![StorageSlot::new(
                get_storage_key(storage_field_path, key),
                Bytes32::new(b.to_be_bytes()),
            )]
        }
        ConstantValue::B256(b) if ty.is_b256(context) => {
            vec![StorageSlot::new(
                get_storage_key(storage_field_path, key),
                Bytes32::new(b.to_be_bytes()),
            )]
        }
        ConstantValue::Array(_a) if ty.is_array(context) => {
            unimplemented!("Arrays in storage have not been implemented yet.")
        }
        _ if ty.is_string_array(context) || ty.is_struct(context) || ty.is_union(context) => {
            // Serialize the constant data in words and add zero words until the number of words
            // is a multiple of 4. This is useful because each storage slot is 4 words.
            // Regarding padding, the top level type in the call is either a string array, struct, or
            // a union. They will properly set the initial padding for the further recursive calls.
            let mut packed = serialize_to_words(
                constant.get_content(context),
                context,
                &ty,
                InByte8Padding::Right,
            );
            packed.extend(vec![
                Bytes8::new([0; 8]);
                packed.len().div_ceil(4) * 4 - packed.len()
            ]);

            assert!(packed.len().is_multiple_of(4));

View on GitHub (pinned to 47e5e902fa)

Solutions

  1. Replace the array field with individual named storage fields (item_0: u64 = 1; item_1: u64 = 2;) or a struct type, which the serializer supports.
  2. Use Vec<T> from std and populate it lazily in an initializer function instead of a compile-time constant.
  3. Pack the data into supported scalar fields (u64/b256) and decode with bitwise operations.
  4. Upgrade to a newer sway release where storage arrays are implemented.

Example fix

// before
storage {
    scores: [u64; 4] = [10, 20, 30, 40],
}

// after
storage {
    scores: Scores = Scores { s0: 10, s1: 20, s2: 30, s3: 40 },
}
// (or use std::vec::Vec<u64> populated at runtime)
Defensive patterns

Strategy: validation

Validate before calling

// Sway-side: reject array-typed storage fields with initializers before building.
// shell: rg -n ':\s*\[[^]]+;\s*\d+\]\s*=' src/*.sway
// Any match must be rewritten (struct fields / Vec) before forc build.

Try / catch

// Panics via unimplemented! - only catch_unwind helps programmatic callers:
let r = std::panic::catch_unwind(|| forc_build_project(path));
if r.is_err() { /* tell user: array storage initializers unsupported on this toolchain */ }

Prevention

When it happens

Trigger: Declaring a storage field with a fixed-size array type AND an initializer, then building the contract: storage { arr: [u64; 4] = [1, 2, 3, 4], } in Sway.

Common situations: Porting Solidity habits (pre-seeded lookup tables in storage); assuming parity between arrays in memory/ABI and arrays in storage; storing token-id or config tables as arrays.

Related errors


AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16). Data as JSON: /api/errors/4c87d4a73f2ff3c4. Report an issue: GitHub.