Skip to content

Commit a4cec2c

Browse files
authored
fix(flatten): sort by loc path and loc start (#302)
ref foundry-rs/foundry#11417 for ```Solidity // SPDX-License-Identifier: MIT pragma solidity >=0.8.19; ... function convert(UD60x18 x) pure returns (uint256 result) { ... } function convert(uint256 x) pure returns (UD60x18 result) { ... } ``` we have items as ``` [ (8378, ItemLocation { path: "lib/prb-math/src/ud60x18/Conversions.sol", start: 462, end: 469 }), (8409, ItemLocation { path: "lib/prb-math/src/ud60x18/Conversions.sol", start: 833, end: 840 }) ] ``` but we sort only by path, hence order could be reversed. Sort also by loc.start to make sure order is preserved
1 parent a30af45 commit a4cec2c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

crates/compilers/src/flatten.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ impl Flattener {
317317
// `loc.path` is expected to be different for each id because there can't be 2
318318
// top-level declarations with the same name in the same file.
319319
//
320-
// Sorting by index loc.path in sorted files to make the renaming process
321-
// deterministic.
320+
// Sorting by index loc.path and loc.start in sorted files to make the renaming
321+
// process deterministic.
322322
ids.sort_by_key(|(_, loc)| {
323-
self.ordered_sources.iter().position(|p| p == &loc.path).unwrap()
323+
(self.ordered_sources.iter().position(|p| p == &loc.path).unwrap(), loc.start)
324324
});
325325
}
326326
for (i, (id, loc)) in ids.iter().enumerate() {

0 commit comments

Comments
 (0)