{"record":{"id":"4c87d4a73f2ff3c4","repo":"FuelLabs/sway","slug":"arrays-in-storage-have-not-been-implemented-yet","errorCode":null,"errorMessage":"Arrays in storage have not been implemented yet.","messagePattern":"Arrays in storage have not been implemented yet\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sway-core/src/ir_generation/storage.rs","lineNumber":226,"sourceCode":"                        .try_into()\n                        .unwrap(),\n                ),\n            )]\n        }\n        ConstantValue::U256(b) if ty.is_uint_of(context, 256) => {\n            vec![StorageSlot::new(\n                get_storage_key(storage_field_path, key),\n                Bytes32::new(b.to_be_bytes()),\n            )]\n        }\n        ConstantValue::B256(b) if ty.is_b256(context) => {\n            vec![StorageSlot::new(\n                get_storage_key(storage_field_path, key),\n                Bytes32::new(b.to_be_bytes()),\n            )]\n        }\n        ConstantValue::Array(_a) if ty.is_array(context) => {\n            unimplemented!(\"Arrays in storage have not been implemented yet.\")\n        }\n        _ if ty.is_string_array(context) || ty.is_struct(context) || ty.is_union(context) => {\n            // Serialize the constant data in words and add zero words until the number of words\n            // is a multiple of 4. This is useful because each storage slot is 4 words.\n            // Regarding padding, the top level type in the call is either a string array, struct, or\n            // a union. They will properly set the initial padding for the further recursive calls.\n            let mut packed = serialize_to_words(\n                constant.get_content(context),\n                context,\n                &ty,\n                InByte8Padding::Right,\n            );\n            packed.extend(vec![\n                Bytes8::new([0; 8]);\n                packed.len().div_ceil(4) * 4 - packed.len()\n            ]);\n\n            assert!(packed.len().is_multiple_of(4));","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/sway-core/src/ir_generation/storage.rs#L208-L244","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Use Vec<T> from std and populate it lazily in an initializer function instead of a compile-time constant.","Pack the data into supported scalar fields (u64/b256) and decode with bitwise operations.","Upgrade to a newer sway release where storage arrays are implemented."],"exampleFix":"// before\nstorage {\n    scores: [u64; 4] = [10, 20, 30, 40],\n}\n\n// after\nstorage {\n    scores: Scores = Scores { s0: 10, s1: 20, s2: 30, s3: 40 },\n}\n// (or use std::vec::Vec<u64> populated at runtime)","handlingStrategy":"validation","validationCode":"// Sway-side: reject array-typed storage fields with initializers before building.\n// shell: rg -n ':\\s*\\[[^]]+;\\s*\\d+\\]\\s*=' src/*.sway\n// Any match must be rewritten (struct fields / Vec) before forc build.","typeGuard":null,"tryCatchPattern":"// Panics via unimplemented! - only catch_unwind helps programmatic callers:\nlet r = std::panic::catch_unwind(|| forc_build_project(path));\nif r.is_err() { /* tell user: array storage initializers unsupported on this toolchain */ }","preventionTips":["Do not declare storage fields as [T; N] with initializers on this sway version.","Use structs or Vec<T> for indexed storage data.","Add a repo grep/CI lint forbidding array types inside the storage block.","Check the sway changelog when upgrading - storage arrays landed in later versions."],"tags":["sway","storage","arrays","compiler","panic"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}