Repository: foundry-rs/foundry (language: rust)

Issue:
forge flatten fails on top-level event declarations
### Component

Forge

### Have you ensured that all of these are up to date?

- [x] Foundry
- [x] Foundryup

### What version of Foundry are you on?

1.0-rc

### What version of Foundryup are you on?

1.0.1

### What command(s) is the bug in?

forge flatten

### Operating System

Linux

### Describe the bug

When trying to flatten a solidity file (one that imports another file), the following error is produced when the compiler encounters an `event` declaration at the top level of a file:

```
Error: Failed to flatten: unknown variant `EventDefinition`, expected one of `PragmaDirective`, `ImportDirective`, `UsingForDirective`, `VariableDeclaration`, `EnumDefinition`, `ErrorDefinition`, `FunctionDefinition`, `StructDefinition`, `UserDefinedValueTypeDefinition`, `ContractDefinition` at line 1 column 13177
```

Event definitions should be allowed at the top level.



Discussion / hints:
@timolson can you provide a minimal example to reproduce the issue? Thank you!
It's super straightforward:

`main.sol`
```
import "./imported.sol";

contract Main {
}
```

`imported.sol`
```
event TestEvent();
```

```
$ forge flatten main.sol 
Error: Failed to flatten: unknown variant `EventDefinition`, expected one of `PragmaDirective`, `ImportDirective`, `UsingForDirective`, `VariableDeclaration`, `EnumDefinition`, `ErrorDefinition`, `FunctionDefinition`, `StructDefinition`, `UserDefinedValueTypeDefinition`, `ContractDefinition` at line 1 column 178
```

Looks like you just need to add `EventDefinition` to your top-level BNF entry.


Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 96322731759c..68d004f1b04f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3783,9 +3783,9 @@ dependencies = [
 
 [[package]]
 name = "foundry-compilers"
-version = "0.13.2"
+version = "0.13.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de23802550de5204eec1a6297296d2fef6b86ea61f33b1667eebd886577caa34"
+checksum = "ac8f0bab060fd7c1764c4be2563e6933d39ec8c2b8a8d6c08aaf45ab29d08310"
 dependencies = [
  "alloy-json-abi",
  "alloy-primitives",
@@ -3820,9 +3820,9 @@ dependencies = [
 
 [[package]]
 name = "foundry-compilers-artifacts"
-version = "0.13.2"
+version = "0.13.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "27f065a1c785b3ec556a7a49a27016fc723bd9a4d8623f521c326f8396df64a6"
+checksum = "b102dd131e939d80cc5c85214d2f0f6ba20ed75cf098019c4d995791b4ebae05"
 dependencies = [
  "foundry-compilers-artifacts-solc",
  "foundry-compilers-artifacts-vyper",
@@ -3830,9 +3830,9 @@ dependencies = [
 
 [[package]]
 name = "foundry-compilers-artifacts-solc"
-version = "0.13.2"
+version = "0.13.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "127e0e788765bc0103eb6b92067843c6ffe660090b2f6fbff1a1441a51939aa0"
+checksum = "db9ef02de4fda04ae3ed098afb6e16edd742d1073f972197a4566836b453bdcd"
 dependencies = [
  "alloy-json-abi",
  "alloy-primitives",
@@ -3854,9 +3854,9 @@ dependencies = [
 
 [[package]]
 name = "foundry-compilers-artifacts-vyper"
-version = "0.13.2"
+version = "0.13.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8764f450332267305440ec399560919e01aa98f23af2c36ac952f9216449cdca"
+checksum = "3bd9d33cbeda448af917105920fefdc3ac42f9ffdaa2d840d58207db7807ea29"
 dependencies = [
  "alloy-json-abi",
  "alloy-primitives",
@@ -3869,9 +3869,9 @@ dependencies = [
 
 [[package]]
 name = "foundry-compilers-core"
-version = "0.13.2"
+version = "0.13.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c59caebbeaeb0e34564c1a404081478a0aadaa8999b57f0befd85965252e074a"
+checksum = "746d121f7b86b84b20e582a27a56c49435768ad3b8005e9afeaf68b53a77fb5c"
 dependencies = [
  "alloy-primitives",
  "cfg-if",
diff --git a/Cargo.toml b/Cargo.toml
index 0ad21d6c143b..44e561c79a36 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -187,7 +187,7 @@ foundry-linking = { path = "crates/linking" }
 
 # solc & compilation utilities
 foundry-block-explorers = { version = "0.11.0", default-features = false }
-foundry-compilers = { version = "0.13.2", default-features = false }
+foundry-compilers = { version = "0.13.3", default-features = false }
 foundry-fork-db = "0.11.0"
 solang-parser = "=0.3.3"
 solar-parse = { version = "=0.1.1", default-features = false }


Test patch: