lang: Fix instruction return type generation with `declare_program!` (#2977)

This commit is contained in:
acheron 2024-05-21 22:04:19 +02:00 committed by GitHub
parent b76d1bf04b
commit 334a44ab7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 66 additions and 44 deletions

View File

@ -32,6 +32,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Fix using `Vec<u8>` type with `declare_program!` ([#2966](https://github.com/coral-xyz/anchor/pull/2966)). - lang: Fix using `Vec<u8>` type with `declare_program!` ([#2966](https://github.com/coral-xyz/anchor/pull/2966)).
- lang: Fix `ProgramError::ArithmeticOverflow` not found error ([#2975](https://github.com/coral-xyz/anchor/pull/2975)). - lang: Fix `ProgramError::ArithmeticOverflow` not found error ([#2975](https://github.com/coral-xyz/anchor/pull/2975)).
- lang: Fix using optional accounts with `declare_program!` ([#2967](https://github.com/coral-xyz/anchor/pull/2967)). - lang: Fix using optional accounts with `declare_program!` ([#2967](https://github.com/coral-xyz/anchor/pull/2967)).
- lang: Fix instruction return type generation with `declare_program!` ([#2977](https://github.com/coral-xyz/anchor/pull/2977)).
### Breaking ### Breaking

View File

@ -50,7 +50,7 @@ fn gen_cpi_instructions(idl: &Idl) -> proc_macro2::TokenStream {
let ty = convert_idl_type_to_syn_type(ty); let ty = convert_idl_type_to_syn_type(ty);
( (
quote! { anchor_lang::Result<Return::<#ty>> }, quote! { anchor_lang::Result<Return::<#ty>> },
quote! { Ok(Return::<#ty> { phantom:: std::marker::PhantomData }) }, quote! { Ok(Return::<#ty> { phantom: std::marker::PhantomData }) },
) )
}, },
None => ( None => (

View File

@ -44,6 +44,56 @@
], ],
"args": [] "args": []
}, },
{
"name": "test_compilation_defined_type_param",
"discriminator": [
61,
118,
87,
242,
137,
97,
90,
223
],
"accounts": [
{
"name": "signer",
"signer": true
}
],
"args": [
{
"name": "_my_account",
"type": {
"defined": {
"name": "MyAccount"
}
}
}
]
},
{
"name": "test_compilation_return_type",
"discriminator": [
174,
51,
51,
121,
52,
61,
38,
28
],
"accounts": [
{
"name": "signer",
"signer": true
}
],
"args": [],
"returns": "bool"
},
{ {
"name": "update", "name": "update",
"discriminator": [ "discriminator": [
@ -81,47 +131,6 @@
} }
] ]
}, },
{
"name": "update_all",
"discriminator": [
205,
139,
239,
66,
134,
131,
110,
182
],
"accounts": [
{
"name": "authority",
"signer": true
},
{
"name": "my_account",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "authority"
}
]
}
}
],
"args": [
{
"name": "my_account",
"type": {
"defined": {
"name": "MyAccount"
}
}
}
]
},
{ {
"name": "update_composite", "name": "update_composite",
"discriminator": [ "discriminator": [

View File

@ -21,10 +21,22 @@ pub mod external {
} }
// Compilation test for whether a defined type (an account in this case) can be used in `cpi` client. // Compilation test for whether a defined type (an account in this case) can be used in `cpi` client.
pub fn update_all(ctx: Context<Update>, my_account: MyAccount) -> Result<()> { pub fn test_compilation_defined_type_param(
*ctx.accounts.my_account = my_account; _ctx: Context<TestCompilation>,
_my_account: MyAccount,
) -> Result<()> {
Ok(()) Ok(())
} }
// Compilation test for whether a custom return type can be specified in `cpi` client
pub fn test_compilation_return_type(_ctx: Context<TestCompilation>) -> Result<bool> {
Ok(true)
}
}
#[derive(Accounts)]
pub struct TestCompilation<'info> {
pub signer: Signer<'info>,
} }
#[derive(Accounts)] #[derive(Accounts)]