From 6bdd11e53b8abf91254b642d947ba70c45e3b6c6 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 13 Oct 2022 03:43:59 +0800 Subject: [PATCH] checker: check error for fn call with extra parenthesis (#16052) --- vlib/v/checker/fn.v | 12 +++++++----- .../checker/tests/fn_call_with_extra_parenthesis.out | 6 ++++++ .../checker/tests/fn_call_with_extra_parenthesis.vv | 6 ++++++ 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 vlib/v/checker/tests/fn_call_with_extra_parenthesis.out create mode 100644 vlib/v/checker/tests/fn_call_with_extra_parenthesis.vv diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 8a317342d2..7247f7b0c1 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -715,11 +715,13 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) } if !found && mut node.left is ast.CallExpr { c.expr(node.left) - sym := c.table.sym(node.left.return_type) - if sym.info is ast.FnType { - node.return_type = sym.info.func.return_type - found = true - func = sym.info.func + if node.left.return_type != 0 { + sym := c.table.sym(node.left.return_type) + if sym.info is ast.FnType { + node.return_type = sym.info.func.return_type + found = true + func = sym.info.func + } } } // already prefixed (mod.fn) or C/builtin/main diff --git a/vlib/v/checker/tests/fn_call_with_extra_parenthesis.out b/vlib/v/checker/tests/fn_call_with_extra_parenthesis.out new file mode 100644 index 0000000000..75449fc204 --- /dev/null +++ b/vlib/v/checker/tests/fn_call_with_extra_parenthesis.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/fn_call_with_extra_parenthesis.vv:5:7: error: expected 1 arguments, but got 0 + 3 | + 4 | fn main() { + 5 | main.doit()(1) + | ~~~~~~ + 6 | } diff --git a/vlib/v/checker/tests/fn_call_with_extra_parenthesis.vv b/vlib/v/checker/tests/fn_call_with_extra_parenthesis.vv new file mode 100644 index 0000000000..a022e0aff1 --- /dev/null +++ b/vlib/v/checker/tests/fn_call_with_extra_parenthesis.vv @@ -0,0 +1,6 @@ +fn doit(i int) { +} + +fn main() { + main.doit()(1) +}