I wrote a smart contract in sway with the following dependencies:
[dependencies]
nft = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.8.1" }
ownership = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.8.1" }
Both of the libraries have an enum with the same name - AccessError
:
After building the contract I get an ABI json file with both of these enums listed:
"types": [
...
{
"typeId": 3,
"type": "enum AccessError",
"components": [
{
"name": "OwnerDoesNotExist",
"type": 0,
"typeArguments": null
},
{
"name": "SenderNotOwner",
"type": 0,
"typeArguments": null
},
{
"name": "SenderNotOwnerOrApproved",
"type": 0,
"typeArguments": null
}
],
"typeParameters": null
},
{
"typeId": 4,
"type": "enum AccessError",
"components": [
{
"name": "CannotReinitialized",
"type": 0,
"typeArguments": null
},
{
"name": "NotOwner",
"type": 0,
"typeArguments": null
}
],
"typeParameters": null
},
...
And when I try to use this ABI in my Rust code
abigen!(Contract(
name = "ContractInstance",
abi = "../contract/out/debug/contract-abi.json"
));
, I get the following error:
$ cargo run
Compiling script v0.1.0 (./script)
error[E0428]: the name `AccessError` is defined multiple times
--> src/model.rs:3:1
|
3 | / abigen!(Contract(
4 | | name = "ContractInstance",
5 | | abi = "../contract/out/debug/contract-abi.json"
6 | | ));
| |__^ `AccessError` redefined here
|
= note: `AccessError` must be defined only once in the type namespace of this module
= note: this error originates in the macro `abigen` (in Nightly builds, run with -Z macro-backtrace for more info)
The problem is gone after renaming one of the AccesError
occurrences manually in the ABI json file, but I think that this behavior should be fixed.
fuelup show
active toolchain
-----------------
beta-3-aarch64-apple-darwin (default)
forc : 0.37.3
- forc-client
- forc-deploy : 0.37.3
- forc-run : 0.37.3
- forc-doc : 0.37.3
- forc-explore : 0.28.1
- forc-fmt : 0.37.3
- forc-index : 0.11.2
- forc-lsp : 0.37.3
- forc-tx : 0.37.3
- forc-wallet : 0.2.2
fuel-core : 0.17.11
fuel-indexer : 0.11.2