From 460869bf10704a48fb97b7eab9afa67aaa5778c1 Mon Sep 17 00:00:00 2001 From: cryptopapi997 <38372048+cryptopapi997@users.noreply.github.com> Date: Tue, 14 May 2024 07:04:22 +0200 Subject: [PATCH] lang: Fix using const generics with `declare_program!` (#2965) --- CHANGELOG.md | 1 + lang/attribute/program/src/declare_program/common.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10196a3b4..0d3da911c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lang/attribute/program/src/declare_program/common.rs b/lang/attribute/program/src/declare_program/common.rs index e276a4fe0..5cd08b87e 100644 --- a/lang/attribute/program/src/declare_program/common.rs +++ b/lang/attribute/program/src/declare_program/common.rs @@ -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::>(); if generics.is_empty() {