Skip to content

sway-fmt formats all fields within a struct instantiation expression into a single line #1493

@Braqzen

Description

@Braqzen

The following example

contract;

use std::hash::*;

abi MyContract {
    fn test() -> bool;
}

struct SentinelTransaction {
    to: b256,
    value: b256,
    data: b256,
    executed: b256,
    approvals: b256,
}

storage {
    sentinel: SentinelTransaction,
}

impl MyContract for Contract {
    fn test() -> bool {
        storage.sentinel = SentinelTransaction {
            to: hash_u64(1, HashMethod::Sha256), 
            value: hash_u64(2, HashMethod::Sha256), 
            data: hash_u64(3, HashMethod::Sha256), 
            executed: hash_u64(4, HashMethod::Sha256), 
            approvals: hash_u64(5, HashMethod::Sha256)
        };
        true
    }
}

formats into

contract;

use std::hash::*;

abi MyContract {
    fn test() -> bool;
}

struct SentinelTransaction {
    to: b256,
    value: b256,
    data: b256,
    executed: b256,
    approvals: b256,
}

storage {
    sentinel: SentinelTransaction,
}

impl MyContract for Contract {
    fn test() -> bool {
        storage.sentinel = SentinelTransaction {
            to: hash_u64(1, HashMethod::Sha256), value: hash_u64(2, HashMethod::Sha256), data: hash_u64(3, HashMethod::Sha256), executed: hash_u64(4, HashMethod::Sha256), approvals: hash_u64(5, HashMethod::Sha256)
        };
        true
    }
}

Preferably it will remain the same as in the "before".

Related: #1210

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions