Need to re-import in order to access functionality
Summary
When importing a type into file2 and using that imported type in a custom type I must reimport the same type (not the custom one) into file1 in order to obtain the same functionality despite never using the type explicitly.
main.sw
contract;
dep utils;
use std::constants::BASE_ASSET_ID;
// uncomment to make this build
// use std::contract_id::ContractId;
use utils::Wrapper;
abi MyContract {
fn test_function() -> bool;
}
impl MyContract for Contract {
fn test_function() -> bool {
let w1 = Wrapper { asset: BASE_ASSET_ID };
let w2 = Wrapper { asset: BASE_ASSET_ID };
// works
// w1 == w2
// fails to find "eq"
w1.asset == w2.asset
}
}
I expect the above to work without having to import ContractId however it fails to build if it is not imported again.
utils.sw
library utils;
use core::ops::Eq;
use std::contract_id::ContractId;
pub struct Wrapper {
asset: ContractId
}
impl Eq for Wrapper {
fn eq(self, other: Self) -> bool {
self.asset == other.asset
}
}
Screenshot

Another instance (from https://github.com/FuelLabs/sway/issues/2322) where this happens is:
contract;
use std::{
address::Address,
chain::auth::msg_sender,
identity::Identity,
result::Result,
};
abi MyContract {
fn test();
}
impl MyContract for Contract {
fn test() {
let sender = msg_sender().unwrap();
if let Identity::Address(addr) = sender {
let lalala = addr.into();
}
}
}
- I need to import
Resultfor thesenderline to pick up on.unwrap(). I thought this was the issue that was resolved for introspection so that e.g.some_func().struct_fieldcould work, likewise I'm pretty sure that this worked before on chained method calls
Also, one thing I noticed is that importing:
use utils::*;
instead of:
use utils::Wrapper;
compiles! So we clearly have logic in the glob import code that is transitive 🤔
Hi @Braqzen, I wasn't able to reproduce the error and I believe that this bug is likely resolved. Can you confirm? I have a PR this PR up. #3710. CC @mohammadfawaz
Hi @Braqzen, I wasn't able to reproduce the error and I believe that this bug is likely resolved. Can you confirm? I have a PR this PR up. #3710. CC @mohammadfawaz
Having directly copy and pasted my previous examples on forc v0.32.2 I have no issues building.