Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syn: Fix IDL named enum variant field being snake_case #2633

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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