1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix panic on fn abc()?{ return error() }

This commit is contained in:
Delyan Angelov 2021-05-29 23:46:29 +03:00
parent d6e462a6ca
commit b29bc9cdce
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 9 additions and 1 deletions

View File

@ -2430,7 +2430,7 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
return func.return_type
}
// `return error(err)` -> `return err`
if fn_name == 'error' {
if fn_name == 'error' && call_expr.args.len == 1 {
arg := call_expr.args[0]
call_expr.args[0].typ = c.expr(arg.expr)
if call_expr.args[0].typ == ast.error_type {

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/error_fn_with_0_args.vv:2:9: error: expected 1 arguments, but got 0
1 | fn abc() ? {
2 | return error()
| ~~~~~~~
3 | }

View File

@ -0,0 +1,3 @@
fn abc() ? {
return error()
}