Skip to content

Commit

Permalink
Lower revert argument
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed Jan 2, 2022
1 parent efd91fb commit 8500697
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/lowering/src/mappers/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ fn func_stmt(context: &mut FnContext, stmt: Node<fe::FuncStmt>) -> Vec<Node<fe::
fe::FuncStmt::Pass => vec![stmt.kind],
fe::FuncStmt::Break => vec![stmt.kind],
fe::FuncStmt::Continue => vec![stmt.kind],
fe::FuncStmt::Revert { .. } => vec![stmt.kind],
fe::FuncStmt::Revert { error } => vec![fe::FuncStmt::Revert {
error: error.map(|expr| expressions::expr(context, expr)),
}],
};
let span = stmt.span;

Expand Down
7 changes: 7 additions & 0 deletions crates/test-files/fixtures/crashes/revert_const.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const FOO: u256 = 0x101

struct Error:
code: u256

fn exit():
revert Error(code = FOO)
1 change: 1 addition & 0 deletions crates/tests/src/crashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ macro_rules! test_file {

test_file! { agroce531 }
test_file! { agroce550 }
test_file! { revert_const }
13 changes: 13 additions & 0 deletions newsfragments/619.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
The argument to `revert` wasn't being lowered by the compiler,
meaning that some `revert` calls would cause a compiler panic
in later stages. For example:

```
const BAD_MOJO: u256 = 0xdeaddead
struct Error:
code: u256
fn fail():
revert Error(code = BAD_MOJO)
```

0 comments on commit 8500697

Please sign in to comment.