Skip to content

Commit 9fbda06

Browse files
authored
fix: allow top level event declarations (#251)
- ref foundry-rs/foundry#9876: add ErrorDefinition as part of SourceUnitPart group
1 parent 6acbb69 commit 9fbda06

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

crates/artifacts/solc/src/ast/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ node_group! {
5757
VariableDeclaration,
5858
EnumDefinition,
5959
ErrorDefinition,
60+
EventDefinition,
6061
FunctionDefinition,
6162
StructDefinition,
6263
UserDefinedValueTypeDefinition,

crates/artifacts/solc/src/ast/visitor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ impl_walk!(SourceUnitPart, |part, visitor| {
9999
SourceUnitPart::ErrorDefinition(error) => {
100100
error.walk(visitor);
101101
}
102+
SourceUnitPart::EventDefinition(event) => {
103+
event.walk(visitor);
104+
}
102105
SourceUnitPart::StructDefinition(struct_) => {
103106
struct_.walk(visitor);
104107
}

crates/compilers/src/flatten.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl Flattener {
320320
let mut ids = ids.clone().into_iter().collect::<Vec<_>>();
321321
if needs_rename {
322322
// `loc.path` is expected to be different for each id because there can't be 2
323-
// top-level eclarations with the same name in the same file.
323+
// top-level declarations with the same name in the same file.
324324
//
325325
// Sorting by index loc.path in sorted files to make the renaming process
326326
// deterministic.

crates/compilers/tests/project.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,3 +4113,44 @@ contract SimpleContract {}
41134113
]
41144114
);
41154115
}
4116+
4117+
// <https://github.com/foundry-rs/foundry/issues/9876>
4118+
#[test]
4119+
fn can_flatten_top_level_event_declaration() {
4120+
let project = TempProject::<MultiCompiler>::dapptools().unwrap();
4121+
4122+
let target = project
4123+
.add_source(
4124+
"A",
4125+
r#"pragma solidity ^0.8.10;
4126+
import "./B.sol";
4127+
contract A { }
4128+
"#,
4129+
)
4130+
.unwrap();
4131+
4132+
project
4133+
.add_source(
4134+
"B",
4135+
r#"
4136+
event TestEvent();
4137+
"#,
4138+
)
4139+
.unwrap();
4140+
4141+
test_flatteners(&project, &target, |result| {
4142+
assert_eq!(
4143+
result,
4144+
r"pragma solidity ^0.8.10;
4145+
4146+
// src/B.sol
4147+
4148+
event TestEvent();
4149+
4150+
// src/A.sol
4151+
4152+
contract A { }
4153+
"
4154+
);
4155+
});
4156+
}

0 commit comments

Comments
 (0)