coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.36k stars 1.25k forks source link

No function or associated item named insert_types, create_type, get_full_path for VecDeque and usize on Anchor 0.30 #2987

Closed megatunger closed 1 month ago

megatunger commented 1 month ago

I could not build the program since upgrade to Anchor 0.30. It happened if I try to add a field with usize or VecDeq type in struct. Here is a simple replication of this issue


#[account]
pub struct Pool {
    pub id: u64,
    pub size: usize,
    pub workers: VecDeque<Pubkey>,
}

Old: Anchor 0.29.0, Solana 1.18.14 -> working

IMG_0058

New: Anchor 0.30.0, Solana 1.18.14 -> not working

IMG_0060

List of errors:

error[E0599]: no function or associated item named insert_types found for struct VecDeque in the current scope error[E0599]: no function or associated item named insert_types found for type usize in the current scope error[E0599]: no function or associated item named create_type found for struct VecDeque in the current scope error[E0599]: no function or associated item named get_full_path found for struct usize in the current scope error[E0599]: no function or associated item named get_full_path found for struct VecDeque in the current scope

acheroncrypto commented 1 month ago

usize and VecDeque types are not supported in the IDL spec. The reason it used to work before 0.30.0 is because IDL generation would just make everything unknown as a defined type, which resulted in build succeeding but also with an unusable IDL. You can verify this by building your program with 0.29.0 and try to use that IDL client side.

You can, however, include any type in the IDL if you implement IdlBuild trait for that type. See "Customization" section of https://github.com/coral-xyz/anchor/pull/2824 and this example.

megatunger commented 1 month ago

Thanks for you explaination!