Skip to content

Commit

Permalink
Allow compilation of contracts that have no public functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf committed Feb 15, 2021
1 parent fee4658 commit f840fff
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
10 changes: 7 additions & 3 deletions compiler/src/yul/runtime/abi_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ pub fn dispatcher(attributes: Vec<FunctionAttributes>) -> yul::Statement {
.map(|arm| dispatch_arm(arm.to_owned()))
.collect::<Vec<_>>();

switch! {
switch (cloadn(0, 4))
[arms...]
if arms.is_empty() {
return statement! { pop(0) };
} else {
switch! {
switch (cloadn(0, 4))
[arms...]
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion compiler/tests/evm_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,12 @@ fn create_contract() {
})
}

#[rstest(fixture_file, contract_name, case("ownable.fe", "Ownable"))]
#[rstest(
fixture_file,
contract_name,
case("ownable.fe", "Ownable"),
case("empty.fe", "Empty")
)]
fn can_deploy_fixture(fixture_file: &str, contract_name: &str) {
with_executor(&|mut executor| {
deploy_contract(&mut executor, fixture_file, contract_name, &[]);
Expand Down
2 changes: 2 additions & 0 deletions compiler/tests/fixtures/empty.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
contract Empty:
lonely: u256
8 changes: 8 additions & 0 deletions newsfragments/219.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Fix bug where compilation of contracts without public functions would result in illegal YUL.

E.g without this change, the following doesn't compile to proper YUL

```
contract Empty:
lonely: u256
```

0 comments on commit f840fff

Please sign in to comment.