parser: make sure methods have names

pull/8561/head
Alexander Medvednikov 2021-02-04 22:15:16 +01:00
parent 5eef730290
commit fdd8c86fdb
1 changed files with 7 additions and 2 deletions

View File

@ -274,8 +274,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
scope: 0 scope: 0
} }
} }
} } else if p.tok.kind in [.plus, .minus, .mul, .div, .mod, .lt, .eq] && p.peek_tok.kind == .lpar {
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() name = p.tok.kind.str() // op_to_fn_name()
if rec_type == table.void_type { if rec_type == table.void_type {
p.error_with_pos('cannot use operator overloading with normal functions', 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 { } 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.error_with_pos('cannot overload `!=`, `>`, `<=` and `>=` as they are auto generated with `==` and`<`',
p.tok.position()) p.tok.position())
} else {
pos := p.tok.position()
p.error_with_pos('expecting method name', pos)
return ast.FnDecl{
scope: 0
}
} }
// <T> // <T>
generic_params := p.parse_generic_params() generic_params := p.parse_generic_params()