Skip to content

Commit

Permalink
lang: Fix using const generics with declare_program! (coral-xyz#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptopapi997 authored May 14, 2024
1 parent 460a161 commit 460869b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions lang/attribute/program/src/declare_program/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 460869b

Please sign in to comment.