anchor icon indicating copy to clipboard operation
anchor copied to clipboard

IDL doesn't support `PhantomData`

Open cryptopapi997 opened this issue 5 months ago • 3 comments

If we define an account like so

use std::marker::PhantomData;

use anchor_lang::prelude::*;

declare_id!("B8v9C4JA5CqMWcoKYfA2hQSEytFxPVk1iWeEjXQxCvS3");

#[program]
pub mod sample {
    use super::*;

    pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
        msg!("Greetings from: {:?}", ctx.program_id);
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    pub data_obj_acc: Account<'info, MyAcc<MyStruct>>,
}

#[account]
pub struct MyAcc<T> {
    _p: PhantomData<T>,
}

#[derive(AnchorDeserialize, AnchorSerialize, Clone)]
pub struct MyStruct {}

it compiles fine if we compile with anchor build --no-idl. If we try to build the idl however, we get a bunch of errors (I'm guessing because the idl tries to include PhantomData in the idl itself but it isn't serializable). I'm not sure if this is intentional or not, but if it isn't it would be nice to support PhantomData.

cryptopapi997 avatar Sep 11 '24 14:09 cryptopapi997