Skip to content

Commit

Permalink
lang: Fix adding derives and reprs to type alias definitions (#3504)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Jan 22, 2025
1 parent 806f214 commit 5d0fe35
Show file tree
Hide file tree
Showing 4 changed files with 3,647 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- lang: Remove a potential panic while getting the IDL in `declare_program!` ([#3458](https://github.com/coral-xyz/anchor/pull/3458)).
- cli: Fix altering user-provided lib names ([#3467](https://github.com/coral-xyz/anchor/pull/3467)).
- idl: Fix missing `program::seed` resolution ([#3474](https://github.com/coral-xyz/anchor/pull/3474)).
- lang: Fix adding `derive`s and `repr`s to type alias definitions in `declare_program!` ([#3504](https://github.com/coral-xyz/anchor/pull/3504)).

### Breaking

Expand Down
28 changes: 17 additions & 11 deletions lang/attribute/program/src/declare_program/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ pub fn convert_idl_type_def_to_ts(
quote!()
};

let ty = match &ty_def.ty {
match &ty_def.ty {
IdlTypeDefTy::Struct { fields } => {
let declare_struct = quote! { pub struct #name #generics };
handle_defined_fields(
let ty = handle_defined_fields(
fields.as_ref(),
|| quote! { #declare_struct; },
|fields| {
Expand All @@ -222,7 +222,14 @@ pub fn convert_idl_type_def_to_ts(
#declare_struct (#(#tys,)*);
}
},
)
);

quote! {
#docs
#attrs
#repr
#ty
}
}
IdlTypeDefTy::Enum { variants } => {
let variants = variants.iter().map(|variant| {
Expand Down Expand Up @@ -252,22 +259,21 @@ pub fn convert_idl_type_def_to_ts(
});

quote! {
#docs
#attrs
#repr
pub enum #name #generics {
#(#variants,)*
}
}
}
IdlTypeDefTy::Type { alias } => {
let alias = convert_idl_type_to_syn_type(alias);
quote! { pub type #name = #alias; }
quote! {
#docs
pub type #name = #alias;
}
}
};

quote! {
#docs
#attrs
#repr
#ty
}
}

Expand Down
Loading

0 comments on commit 5d0fe35

Please sign in to comment.