Skip to content

Commit

Permalink
Allow returns values to be ignored in try catch
Browse files Browse the repository at this point in the history
A try catch statement does not need to decode the return values if it is not interested.

Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung committed Jun 20, 2023
1 parent 0221f20 commit d60bfbd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/sema/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@ fn try_catch(
func_returns = vec![];
}

if returns.len() != func_returns.len() {
if !returns.is_empty() && returns.len() != func_returns.len() {
diagnostics.push(Diagnostic::error(
expr.loc(),
format!(
Expand Down
2 changes: 1 addition & 1 deletion tests/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn ethereum_solidity_tests() {
})
.sum();

assert_eq!(errors, 1038);
assert_eq!(errors, 1032);
}

fn set_file_contents(source: &str, path: &Path) -> (FileResolver, Vec<String>) {
Expand Down
26 changes: 26 additions & 0 deletions tests/substrate_tests/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ fn try_catch_external_calls() {
runtime.constructor(0, Vec::new());
runtime.function_expect_failure("test", Vec::new());

let mut runtime = build_solidity(
r##"
contract c {
function test() public {
other o = new other();
int32 x = 0;
try o.test() {
x = 1;
} catch (bytes c) {
x = 2;
}
assert(x == 2);
}
}
contract other {
function test() public returns (int32, bool) {
revert("foo");
}
}
"##,
);

runtime.constructor(0, Vec::new());
runtime.function("test", Vec::new());

let mut runtime = build_solidity(
r##"
contract c {
Expand Down

0 comments on commit d60bfbd

Please sign in to comment.