Skip to content

Commit baf27bf

Browse files
committed
Deduplicate external contracts by full path
1 parent 18cf080 commit baf27bf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

scarb/src/compiler/compilers/starknet_contract/compiler.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,18 @@ pub fn find_project_contracts(
332332
Vec::new()
333333
};
334334

335-
Ok(internal_contracts
335+
// Deduplicate found contracts by contract path.
336+
let mut contracts_found = internal_contracts
336337
.into_iter()
337338
.chain(external_contracts)
339+
.map(|decl| (decl.module_id().full_path(db.upcast()), decl))
340+
.sorted_by_key(|(path, _)| path.clone())
341+
.collect_vec();
342+
contracts_found.dedup_by_key(|(path, _)| path.clone());
343+
344+
Ok(contracts_found
345+
.into_iter()
346+
.map(|(_path, decl)| decl)
338347
.collect())
339348
}
340349

scarb/tests/build_starknet_external_contracts.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,11 @@ fn can_dedup_contract_reexports() {
572572
[[target.starknet-contract]]
573573
"#})
574574
.dep_starknet()
575-
.lib_cairo("pub mod a; pub use a::Balance;")
575+
.lib_cairo(indoc! {r#"
576+
// Note that Balance contract can be accessed both through mod tree and the reexport.
577+
pub mod a;
578+
pub use a::Balance;
579+
"#})
576580
.src("src/a.cairo", BALANCE_CONTRACT)
577581
.build(&hello);
578582

0 commit comments

Comments
 (0)