Skip to content

Commit

Permalink
syn: Fix IDL named enum variant field being snake_case (#2633)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Sep 21, 2023
1 parent fa9f960 commit 3c6fc2b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- ts: Load workspace programs on-demand rather than loading all of them at once ([#2579](https://github.com/coral-xyz/anchor/pull/2579)).
- lang: Fix `associated_token::token_program` constraint ([#2603](https://github.com/coral-xyz/anchor/pull/2603)).
- cli: Fix `anchor account` command panicking outside of workspace ([#2620](https://github.com/coral-xyz/anchor/pull/2620)).
- lang: IDL named enum variant fields are now camelCase as opposed to snake_case, consistent with the other IDL types ([#2633](https://github.com/coral-xyz/anchor/pull/2633)).

### Breaking

Expand Down
3 changes: 2 additions & 1 deletion lang/syn/src/idl/parse/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ fn parse_ty_defs(ctx: &CrateContext, no_docs: bool) -> Result<Vec<IdlTypeDefinit
.named
.iter()
.map(|f: &syn::Field| {
let name = f.ident.as_ref().unwrap().to_string();
let name =
f.ident.as_ref().unwrap().to_string().to_mixed_case();
let doc = if !no_docs {
docs::parse(&f.attrs)
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/idl/idls/parse.json
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,14 @@
"name": "Named",
"fields": [
{
"name": "bool_field",
"name": "boolField",
"docs": [
"A bool field inside a struct tuple kind"
],
"type": "bool"
},
{
"name": "u8_field",
"name": "u8Field",
"type": "u8"
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/idl/programs/client-interactions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub struct EnumAccount {
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Debug, Eq, PartialEq)]
pub enum MyEnum {
Unit,
Named { x: u64, y: u64 },
Named { point_x: u64, point_y: u64 },
Unnamed(u8, u8, u16, u16),
UnnamedStruct(MyStruct),
}
Expand Down
10 changes: 5 additions & 5 deletions tests/idl/tests/client-interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ describe("Client interactions", () => {
assert.deepEqual(unit.enumField.unit, {});

// Named
const x = new anchor.BN(1);
const y = new anchor.BN(2);
const named = await testAccountEnum({ named: { x, y } });
assert(named.enumField.named.x.eq(x));
assert(named.enumField.named.y.eq(y));
const pointX = new anchor.BN(1);
const pointY = new anchor.BN(2);
const named = await testAccountEnum({ named: { pointX, pointY } });
assert(named.enumField.named.pointX.eq(pointX));
assert(named.enumField.named.pointY.eq(pointY));

// Unnamed
const tupleArg = [1, 2, 3, 4] as const;
Expand Down

1 comment on commit 3c6fc2b

@vercel
Copy link

@vercel vercel bot commented on 3c6fc2b Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-git-master-200ms.vercel.app
anchor-docs-200ms.vercel.app
anchor-lang.com
www.anchor-lang.com

Please sign in to comment.