sway icon indicating copy to clipboard operation
sway copied to clipboard

Inconsistent formatting of Sway onto a new line

Open Braqzen opened this issue 2 years ago • 0 comments

There is a strange formatting bug which I haven't been able to pinpoint within 30 minutes.

Using forc 0.48.1 and the following snippet run forc fmt

library;

use std::{constants::ZERO_B256, inputs::input_message_data};

const OFFSET_AMOUNT = 160;

pub struct MessageData {
    amount: b256,
}

impl MessageData {
    pub fn parse(msg_idx: u64) {
        let mut msg_data = Self {
            amount: ZERO_B256,
        };

        // Number of characters in line: 68 
        msg_data.amount = input_message_data(msg_idx, OFFSET_AMOUNT).into();

        // Number of characters in line: 62 
        msg_data.amount = input_message_data(0, OFFSET_AMOUNT).into();

        // Number of characters in line: 56 
        msg_data.amount = input_message_data(msg_idx, 0).into();

        // Number of characters in line: 64
        let a: b256 = input_message_data(msg_idx, OFFSET_AMOUNT).into();

        // Number of characters in line: 89 
        let abcdefghijklmnopqrstuvwxyz: b256 = input_message_data(msg_idx, OFFSET_AMOUNT).into();
    }
}

to produce the following formatted code

library;

use std::{constants::ZERO_B256, inputs::input_message_data};

const OFFSET_AMOUNT = 160;

pub struct MessageData {
    amount: b256,
}

impl MessageData {
    pub fn parse(msg_idx: u64) {
        let mut msg_data = Self {
            amount: ZERO_B256,
        };

        // Number of characters in line: 68 
        msg_data.amount = input_message_data(msg_idx, OFFSET_AMOUNT)
            .into();

        // Number of characters in line: 62 
        msg_data.amount = input_message_data(0, OFFSET_AMOUNT)
            .into();

        // Number of characters in line: 56 
        msg_data.amount = input_message_data(msg_idx, 0).into();

        // Number of characters in line: 64
        let a: b256 = input_message_data(msg_idx, OFFSET_AMOUNT).into();

        // Number of characters in line: 89 
        let abcdefghijklmnopqrstuvwxyz: b256 = input_message_data(msg_idx, OFFSET_AMOUNT).into();
    }
}

Notice how the first 2 assignments put the .into() onto a new line while the rest do not.

Strangely, if you delete the MessageData struct and all code related to assigning to it and change the parse() associated function to be a stand alone function then the .into() is not moved onto a new line.

Braqzen avatar Jan 16 '24 15:01 Braqzen