diff --git a/CHANGELOG.md b/CHANGELOG.md index 7161132da..a89ca86a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ The minor version will be incremented upon a breaking change and the patch versi - cli: Fix upgradeable program clones ([#3010](https://github.com/coral-xyz/anchor/pull/3010)). - ts: Fix using IDLs that have defined types as generic arguments ([#3016](https://github.com/coral-xyz/anchor/pull/3016)). - idl: Fix generation with unsupported expressions ([#3033](https://github.com/coral-xyz/anchor/pull/3033)). +- idl: Fix using `address` constraint with field expressions ([#3034](https://github.com/coral-xyz/anchor/pull/3034)). ### Breaking diff --git a/lang/syn/src/idl/accounts.rs b/lang/syn/src/idl/accounts.rs index 016df76a0..c944c26f5 100644 --- a/lang/syn/src/idl/accounts.rs +++ b/lang/syn/src/idl/accounts.rs @@ -161,6 +161,7 @@ fn get_address(acc: &Field) -> TokenStream { .address .as_ref() .map(|constraint| &constraint.address) + .filter(|address| !matches!(address, syn::Expr::Field(_))) .map(|address| quote! { Some(#address.to_string()) }) .unwrap_or_else(|| quote! { None }), } diff --git a/tests/relations-derivation/programs/relations-derivation/src/lib.rs b/tests/relations-derivation/programs/relations-derivation/src/lib.rs index c2bf74af0..9d8383f22 100644 --- a/tests/relations-derivation/programs/relations-derivation/src/lib.rs +++ b/tests/relations-derivation/programs/relations-derivation/src/lib.rs @@ -16,12 +16,18 @@ pub mod relations_derivation { ctx.accounts.account.bump = ctx.bumps.account; Ok(()) } + pub fn test_relation(_ctx: Context) -> Result<()> { Ok(()) } + pub fn test_seed_constant(_ctx: Context) -> Result<()> { Ok(()) } + + pub fn test_address_relation(_ctx: Context) -> Result<()> { + Ok(()) + } } #[derive(Accounts)] @@ -80,6 +86,14 @@ pub struct TestSeedConstant<'info> { system_program: Program<'info, System>, } +#[derive(Accounts)] +pub struct TestAddressRelation<'info> { + #[account(address = my_account.my_account)] + account: UncheckedAccount<'info>, + #[account(seeds = [b"seed"], bump = my_account.bump)] + my_account: Account<'info, MyAccount>, +} + #[account] pub struct MyAccount { pub my_account: Pubkey, diff --git a/tests/relations-derivation/tests/typescript.spec.ts b/tests/relations-derivation/tests/typescript.spec.ts index f5d326f97..5f76aaa45 100644 --- a/tests/relations-derivation/tests/typescript.spec.ts +++ b/tests/relations-derivation/tests/typescript.spec.ts @@ -44,4 +44,9 @@ describe("typescript", () => { it("Can use relations derivation with seed constant", async () => { await program.methods.testSeedConstant().accounts({}).rpc(); }); + + it("Can use relations derivation with `address` constraint", () => { + // Only compile test for now since the IDL spec doesn't currently support field access + // expressions for the `address` constraint + }); });