Forráskód Böngészése

lang: Fix using `data` as an instruction parameter name in `declare_program!` (#3574)

acheron 7 hónapja
szülő
commit
dac533e9c4

+ 1 - 0
CHANGELOG.md

@@ -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
 

+ 2 - 1
lang/attribute/program/src/declare_program/mods/cpi.rs

@@ -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);

+ 25 - 0
tests/declare-program/idls/external.json

@@ -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": [

+ 10 - 0
tests/declare-program/programs/external/src/lib.rs

@@ -1,3 +1,5 @@
+#![allow(unused_variables)]
+
 use anchor_lang::prelude::*;
 
 declare_id!("Externa111111111111111111111111111111111111");
@@ -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(())