Skip to content

Commit 6c1a844

Browse files
committed
abi.decode("", ()) has no returns
This should be compiled as: function returning void Fixes: #1727 Signed-off-by: Sean Young <sean@mess.org>
1 parent 07ad1a1 commit 6c1a844

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

src/codegen/expression.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3198,7 +3198,12 @@ pub fn emit_function_call(
31983198
args,
31993199
} => {
32003200
let data = expression(&args[0], cfg, caller_contract_no, func, ns, vartab, opt);
3201-
abi_decode(loc, &data, tys, ns, vartab, cfg, None)
3201+
3202+
if tys.len() == 1 && tys[0] == Type::Void {
3203+
vec![Expression::Poison]
3204+
} else {
3205+
abi_decode(loc, &data, tys, ns, vartab, cfg, None)
3206+
}
32023207
}
32033208
_ => unreachable!(),
32043209
}

src/sema/builtin.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,24 +1135,30 @@ pub(super) fn resolve_namespace_call(
11351135
let mut tys = Vec::new();
11361136
let mut broken = false;
11371137

1138-
for arg in parameter_list_to_expr_list(&args[1], diagnostics)? {
1139-
let ty = ns.resolve_type(
1140-
context.file_no,
1141-
context.contract_no,
1142-
ResolveTypeContext::None,
1143-
arg.strip_parentheses(),
1144-
diagnostics,
1145-
)?;
1138+
let ty_exprs = parameter_list_to_expr_list(&args[1], diagnostics)?;
11461139

1147-
if ty.is_mapping() || ty.is_recursive(ns) {
1148-
diagnostics.push(Diagnostic::error(
1140+
if ty_exprs.is_empty() {
1141+
tys.push(Type::Void);
1142+
} else {
1143+
for arg in ty_exprs {
1144+
let ty = ns.resolve_type(
1145+
context.file_no,
1146+
context.contract_no,
1147+
ResolveTypeContext::None,
1148+
arg.strip_parentheses(),
1149+
diagnostics,
1150+
)?;
1151+
1152+
if ty.is_mapping() || ty.is_recursive(ns) {
1153+
diagnostics.push(Diagnostic::error(
11491154
*loc,
11501155
format!("Invalid type '{}': mappings and recursive types cannot be abi decoded or encoded", ty.to_string(ns))
11511156
));
1152-
broken = true;
1153-
}
1157+
broken = true;
1158+
}
11541159

1155-
tys.push(ty);
1160+
tys.push(ty);
1161+
}
11561162
}
11571163

11581164
return if broken {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
contract C {
2+
function g() public pure {
3+
abi.decode("abc", ());
4+
}
5+
}
6+
7+
// ---- Expect: diagnostics ----
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
contract C {
2+
function f() public pure {
3+
int a =abi.decode("abc", ());
4+
}
5+
}
6+
7+
// ---- Expect: diagnostics ----
8+
// error: 3:16-37: function or method does not return a value

0 commit comments

Comments
 (0)