sway icon indicating copy to clipboard operation
sway copied to clipboard

Regression: top-down file parsing forces code to be declared in specific areas of the file

Open Braqzen opened this issue 1 year ago • 0 comments

Forc 0.52.0 but upgraded from v49 or so where this was also an issue.

Struct A has 2 impl blocks. One commented out at the top and another lower down the file. If you comment out the bottom impl and use the top impl for A then Self { field: B::new() } within A will complain about new() not being a part of B. If you comment out the top impl and use the bottom (as in this snippet) then it compiles.

Not only is this a regression from some number of months ago but also the message is unclear as it only states that new() cannot be found / is not part of B when it clearly is.

contract;

struct A {
    field: B
}

// impl A {
//     fn new() -> Self {
//         Self { field: B::new() }
//     }
// }

struct B {
    field: u64
}

impl B {
    fn new() -> Self {
        Self { field: 0 }
    }
}

impl A {
    fn new() -> Self {
        Self { field: B::new() }
    }
}

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

impl MyContract for Contract {
    fn test_function() -> bool {
        true
    }
}

Braqzen avatar Mar 30 '24 15:03 Braqzen