Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower revert argument #619

Merged
merged 1 commit into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract Foo:
return 3 * 10
else:
if true:
revert Bar(val=THREE)
revert Bar(val=3)



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)
```