Skip to content

Commit

Permalink
checker: fix panic on fn abc()?{ return error() }
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed May 29, 2021
1 parent d6e462a commit b29bc9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/checker/checker.v
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/checker/tests/error_fn_with_0_args.out
@@ -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 | }
3 changes: 3 additions & 0 deletions vlib/v/checker/tests/error_fn_with_0_args.vv
@@ -0,0 +1,3 @@
fn abc() ? {
return error()
}

0 comments on commit b29bc9c

Please sign in to comment.