FuelLabs / sway

🌴 Empowering everyone to build reliable and efficient smart contracts.
https://docs.fuel.network/docs/sway/
Apache License 2.0
62.76k stars 5.36k forks source link

Associated constants must be declared in order if they are mutually dependent #6537

Open ironcev opened 2 weeks ago

ironcev commented 2 weeks ago

Unlike module constants that can be used in declarations of other module constants regardless of their declaration order, associated constants must be declared in order if they are mutually dependent.

E.g., this works:

const B: u8 = A;  // <<<---- OK. A is declared after B but that doesn't matter.
const A: u8 = 0;

But this doesn't:

struct S {}

impl S {
    const B: u8 = Self::A; // ERROR: Could not find symbol "A" in this scope.
    const A: u8 = 0;
}

When fixing this issue, adjust the recursive_const_... tests which are linked to this issue via GitHub link in the test TODO.