Skip to content

Commit dac533e

Browse files
lang: Fix using data as an instruction parameter name in declare_program! (#3574)
1 parent b6b4f11 commit dac533e

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ The minor version will be incremented upon a breaking change and the patch versi
118118
- idl: Fix using `Pubkey` constants with `seeds::program` ([#3559](https://github.com/coral-xyz/anchor/pull/3559)).
119119
- lang: Fix instructions with no accounts causing compilation errors when using `declare_program!` ([#3567](https://github.com/coral-xyz/anchor/pull/3567)).
120120
- idl: Fix using account or arg values for `seeds::program` ([#3570](https://github.com/coral-xyz/anchor/pull/3570)).
121+
- lang: Fix using `data` as an instruction parameter name in `declare_program!` ([#3574](https://github.com/coral-xyz/anchor/pull/3574)).
121122

122123
### Breaking
123124

lang/attribute/program/src/declare_program/mods/cpi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ fn gen_cpi_instructions(idl: &Idl) -> proc_macro2::TokenStream {
7171
#(#args),*
7272
) -> #ret_type {
7373
let ix = {
74+
let ix = internal::args::#arg_value;
7475
let mut data = Vec::with_capacity(256);
7576
data.extend_from_slice(&#discriminator);
76-
AnchorSerialize::serialize(&internal::args::#arg_value, &mut data)
77+
AnchorSerialize::serialize(&ix, &mut data)
7778
.map_err(|_| anchor_lang::error::ErrorCode::InstructionDidNotSerialize)?;
7879

7980
let accounts = ctx.to_account_metas(None);

tests/declare-program/idls/external.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@
4444
],
4545
"args": []
4646
},
47+
{
48+
"name": "test_compilation_data_as_parameter_name",
49+
"discriminator": [
50+
225,
51+
145,
52+
68,
53+
92,
54+
146,
55+
206,
56+
248,
57+
206
58+
],
59+
"accounts": [
60+
{
61+
"name": "signer",
62+
"signer": true
63+
}
64+
],
65+
"args": [
66+
{
67+
"name": "data",
68+
"type": "bytes"
69+
}
70+
]
71+
},
4772
{
4873
"name": "test_compilation_defined_type_param",
4974
"discriminator": [

tests/declare-program/programs/external/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_variables)]
2+
13
use anchor_lang::prelude::*;
24

35
declare_id!("Externa111111111111111111111111111111111111");
@@ -46,6 +48,14 @@ pub mod external {
4648
Ok(true)
4749
}
4850

51+
// Compilation test for whether `data` can be used as an instruction parameter name
52+
pub fn test_compilation_data_as_parameter_name(
53+
_ctx: Context<TestCompilation>,
54+
data: Vec<u8>,
55+
) -> Result<()> {
56+
Ok(())
57+
}
58+
4959
// Compilation test for an instruction with no accounts
5060
pub fn test_compilation_no_accounts(_ctx: Context<TestCompilationNoAccounts>) -> Result<()> {
5161
Ok(())

0 commit comments

Comments
 (0)