From fdd8c86fdbd0ca788b8655096a41457b6e71be66 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 4 Feb 2021 22:15:16 +0100 Subject: [PATCH] parser: make sure methods have names --- vlib/v/parser/fn.v | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 8b7421a712..a66019969f 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -274,8 +274,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { scope: 0 } } - } - if p.tok.kind in [.plus, .minus, .mul, .div, .mod, .lt, .eq] && p.peek_tok.kind == .lpar { + } else if p.tok.kind in [.plus, .minus, .mul, .div, .mod, .lt, .eq] && p.peek_tok.kind == .lpar { name = p.tok.kind.str() // op_to_fn_name() if rec_type == table.void_type { p.error_with_pos('cannot use operator overloading with normal functions', @@ -285,6 +284,12 @@ fn (mut p Parser) fn_decl() ast.FnDecl { } else if p.tok.kind in [.ne, .gt, .ge, .le] && p.peek_tok.kind == .lpar { p.error_with_pos('cannot overload `!=`, `>`, `<=` and `>=` as they are auto generated with `==` and`<`', p.tok.position()) + } else { + pos := p.tok.position() + p.error_with_pos('expecting method name', pos) + return ast.FnDecl{ + scope: 0 + } } // generic_params := p.parse_generic_params()