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

Compiler panics when an associated constant is initialized to a const-eval associated function #6538

Open ironcev opened 2 weeks ago

ironcev commented 2 weeks ago

When an associated constant is initialized to a const-eval associated function like in the below example, compiler panics with:

thread 'main' panicked at sway-core/src/semantic_analysis/type_check_analysis.rs:64:44:
called `Option::unwrap()` on a `None` value
library;

struct S {}

impl S {
    fn bar() -> u8 {
        0
    }
}

impl S {
    const S_ASSOC: u8 = Self::bar();
}

Panicking is also there if it is initialized with S::bar().

When fixing this issue, adjust the associated_const_in_decls_of_other_constants test which is linked to this issue via GitHub link in the test TODO.