lang: Fix using const generics with `declare_program!` (#2965)

This commit is contained in:
cryptopapi997 2024-05-14 07:04:22 +02:00 committed by GitHub
parent 460a16171a
commit 460869bf10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -26,6 +26,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- idl: Fix path resolution of the `Cargo.lock` of the project when generating idls for external types ([#2946](https://github.com/coral-xyz/anchor/pull/2946)).
- idl: Fix potential panic on external type resolution ([#2954](https://github.com/coral-xyz/anchor/pull/2954)).
- lang: Fix using defined types in instruction parameters with `declare_program!` ([#2959](https://github.com/coral-xyz/anchor/pull/2959)).
- lang: Fix using const generics with `declare_program!` ([#2965](https://github.com/coral-xyz/anchor/pull/2965)).
### Breaking

View File

@ -104,8 +104,15 @@ pub fn convert_idl_type_def_to_ts(
.generics
.iter()
.map(|generic| match generic {
IdlTypeDefGeneric::Type { name } => format_ident!("{name}"),
IdlTypeDefGeneric::Const { name, ty } => format_ident!("{name}: {ty}"),
IdlTypeDefGeneric::Type { name } => {
let name = format_ident!("{}", name);
quote! { #name }
}
IdlTypeDefGeneric::Const { name, ty } => {
let name = format_ident!("{}", name);
let ty = format_ident!("{}", ty);
quote! { const #name: #ty }
}
})
.collect::<Vec<_>>();
if generics.is_empty() {