coral-xyz / anchor

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

bug: `<account> not found in this scope` when putting brackets around it in constraint #3031

Closed esolskjaer closed 2 weeks ago

esolskjaer commented 2 weeks ago

If we try to define a constraint where we put an account in a subscope, anchor will fail to compile with <account> not found in this scope. This was not the case in 0.29.0 and is a problem for trying to do things like the following (the error arises in the seeds constraint because we add 1 to field of DemoAcc in a subscope.

#[derive(Accounts)]
pub struct Demo<'info> {
    #[account(mut)]
    pub authority: Signer<'info>,
    #[account(
        seeds = [&authority.key().to_bytes(),],
        bump,
    )]
    pub demo: Account<'info, DemoAcc>,
    #[account(
        // Error here!
        seeds =  [&(demo.field + 1).to_le_bytes(),],
        bump,
    )]
    /// CHECK: Just for demo
    pub a: AccountInfo<'info>,
}

#[account]
pub struct DemoAcc {
    pub field: u32,
}
acheroncrypto commented 2 weeks ago

It's not currently possible to describe math logic for seeds in the IDL.

As a workaround, you can disable the resolution feature in Anchor.toml:

[features]
resolution = false

Closing, as it's a duplicate of https://github.com/coral-xyz/anchor/issues/2933.