FuelLabs / sway

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

Trait constraint error does not always mention the exact constrained type #6496

Open ironcev opened 2 months ago

ironcev commented 2 months ago

In the following example, compiler will properly reject the code in the main function saying that "Trait "MyTrait1" is not implemented for type". However, in the first case, the type will be the expected "u32", but in the second the whole "Option".

script;

trait MyTrait1 {
    fn foo();
}

fn bar<T>() -> Option<T> where T: MyTrait1 {
    None
}

fn main(){
    let x: Option<u32> = bar();
    //                   ^^^ Trait "MyTrait1" is not implemented for type "u32".    <<<--- OK: u32.
    let x = bar::<Option<u32>>();
    //      ^^^^^^^^^^^^^^^^^^ Trait "MyTrait1" is not implemented for type "Option<u32>".   <<<--- WRONG: Option<u32>.
}