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

fix(abigen): safe ident field names #989

Merged
merged 1 commit into from
Mar 5, 2022
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
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() };
}