From e7e5abcd0d5b5a9f811e7eb1c682ea82c5733450 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 3 May 2022 07:51:28 +0200 Subject: [PATCH] fix(solc): ensure std json sources are unique (#1210) --- ethers-solc/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ethers-solc/src/lib.rs b/ethers-solc/src/lib.rs index c2fcd705..69ab0e6d 100644 --- a/ethers-solc/src/lib.rs +++ b/ethers-solc/src/lib.rs @@ -3,7 +3,7 @@ pub mod artifacts; pub mod sourcemap; pub use artifacts::{CompilerInput, CompilerOutput, EvmVersion}; -use std::collections::BTreeMap; +use std::collections::{BTreeMap, HashSet}; mod artifact_output; pub mod cache; @@ -440,11 +440,17 @@ impl Project { let target_index = graph.files().get(target).ok_or_else(|| { SolcError::msg(format!("cannot resolve file at {:?}", target.display())) })?; + let mut sources = Vec::new(); + let mut unique_paths = HashSet::new(); let (path, source) = graph.node(*target_index).unpack(); + unique_paths.insert(path.clone()); sources.push((path, source)); sources.extend( - graph.all_imported_nodes(*target_index).map(|index| graph.node(index).unpack()), + graph + .all_imported_nodes(*target_index) + .map(|index| graph.node(index).unpack()) + .filter(|(p, _)| unique_paths.insert(p.to_path_buf())), ); let root = self.root();