diff --git a/compiler/src/yul/runtime/abi_dispatcher.rs b/compiler/src/yul/runtime/abi_dispatcher.rs index 4690dc593c..5be0f5e36c 100644 --- a/compiler/src/yul/runtime/abi_dispatcher.rs +++ b/compiler/src/yul/runtime/abi_dispatcher.rs @@ -16,9 +16,13 @@ pub fn dispatcher(attributes: Vec) -> yul::Statement { .map(|arm| dispatch_arm(arm.to_owned())) .collect::>(); - switch! { - switch (cloadn(0, 4)) - [arms...] + if arms.is_empty() { + return statement! { pop(0) }; + } else { + switch! { + switch (cloadn(0, 4)) + [arms...] + } } } diff --git a/compiler/tests/evm_contracts.rs b/compiler/tests/evm_contracts.rs index fd5b66b0ac..97a494988d 100644 --- a/compiler/tests/evm_contracts.rs +++ b/compiler/tests/evm_contracts.rs @@ -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, &[]); diff --git a/compiler/tests/fixtures/empty.fe b/compiler/tests/fixtures/empty.fe new file mode 100644 index 0000000000..2dd735eac7 --- /dev/null +++ b/compiler/tests/fixtures/empty.fe @@ -0,0 +1,2 @@ +contract Empty: + lonely: u256 \ No newline at end of file diff --git a/newsfragments/219.bugfix.md b/newsfragments/219.bugfix.md new file mode 100644 index 0000000000..6728952d10 --- /dev/null +++ b/newsfragments/219.bugfix.md @@ -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 +``` \ No newline at end of file