Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- idl: Fix using `Pubkey` constants with `seeds::program` ([#3559](https://github.com/coral-xyz/anchor/pull/3559)).
- lang: Fix instructions with no accounts causing compilation errors when using `declare_program!` ([#3567](https://github.com/coral-xyz/anchor/pull/3567)).
- idl: Fix using account or arg values for `seeds::program` ([#3570](https://github.com/coral-xyz/anchor/pull/3570)).
- lang: Fix using `data` as an instruction parameter name in `declare_program!` ([#3574](https://github.com/coral-xyz/anchor/pull/3574)).

### Breaking

Expand Down
3 changes: 2 additions & 1 deletion lang/attribute/program/src/declare_program/mods/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ fn gen_cpi_instructions(idl: &Idl) -> proc_macro2::TokenStream {
#(#args),*
) -> #ret_type {
let ix = {
let ix = internal::args::#arg_value;
let mut data = Vec::with_capacity(256);
data.extend_from_slice(&#discriminator);
AnchorSerialize::serialize(&internal::args::#arg_value, &mut data)
AnchorSerialize::serialize(&ix, &mut data)
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotSerialize)?;

let accounts = ctx.to_account_metas(None);
Expand Down
25 changes: 25 additions & 0 deletions tests/declare-program/idls/external.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@
],
"args": []
},
{
"name": "test_compilation_data_as_parameter_name",
"discriminator": [
225,
145,
68,
92,
146,
206,
248,
206
],
"accounts": [
{
"name": "signer",
"signer": true
}
],
"args": [
{
"name": "data",
"type": "bytes"
}
]
},
{
"name": "test_compilation_defined_type_param",
"discriminator": [
Expand Down
10 changes: 10 additions & 0 deletions tests/declare-program/programs/external/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unused_variables)]

use anchor_lang::prelude::*;

declare_id!("Externa111111111111111111111111111111111111");
Expand Down Expand Up @@ -46,6 +48,14 @@ pub mod external {
Ok(true)
}

// Compilation test for whether `data` can be used as an instruction parameter name
pub fn test_compilation_data_as_parameter_name(
_ctx: Context<TestCompilation>,
data: Vec<u8>,
) -> Result<()> {
Ok(())
}

// Compilation test for an instruction with no accounts
pub fn test_compilation_no_accounts(_ctx: Context<TestCompilationNoAccounts>) -> Result<()> {
Ok(())
Expand Down
Loading