Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix(abigen): safe ident field names
Browse files Browse the repository at this point in the history
  • Loading branch information
oblique committed Mar 5, 2022
1 parent 9626cc1 commit 1efe898
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@

## ethers-contract-abigen

### Unreleased

- Generate correct bindings of struct's field names that are reserved words
[#989](https://github.com/gakonst/ethers-rs/pull/989).

### 0.6.0

- Add `MultiAbigen` to generate a series of contract bindings that can be kept in the repo
[#724](https://github.com/gakonst/ethers-rs/pull/724).
- Add provided `event_derives` to call and event enums as well
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Context {
if is_tuple {
fields.push(ty);
} else {
let field_name = util::ident(&field.name().to_snake_case());
let field_name = util::safe_ident(&field.name().to_snake_case());
fields.push(quote! { pub #field_name: #ty });
}
}
Expand Down Expand Up @@ -155,7 +155,7 @@ impl Context {
let mut fields = Vec::with_capacity(sol_struct.fields().len());
let mut param_types = Vec::with_capacity(sol_struct.fields().len());
for field in sol_struct.fields() {
let field_name = util::ident(&field.name().to_snake_case());
let field_name = util::safe_ident(&field.name().to_snake_case());
match field.r#type() {
FieldType::Elementary(ty) => {
param_types.push(ty.clone());
Expand Down
12 changes: 12 additions & 0 deletions ethers-contract/tests/abigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,15 @@ fn can_gen_multi_etherscan() {
let _contract = MyContract::new(Address::default(), Arc::clone(&provider));
let _contract = MyContract2::new(Address::default(), provider);
}

#[test]
fn can_gen_reserved_word_field_names() {
abigen!(
Test,
r#"[
struct Foo { uint256 ref; }
]"#,
);

let _foo = Foo { ref_: U256::default() };
}

0 comments on commit 1efe898

Please sign in to comment.