1 | p.fn_language = language |
2 | } |
3 | mut name := '' |
4 | + mut type_sym := p.table.sym(rec.typ) |
5 | name_pos := p.tok.pos() |
6 | if p.tok.kind == .name { |
7 | // TODO high order fn |
8 | scope: 0 |
9 | } |
10 | } |
11 | - type_sym := p.table.sym(rec.typ) |
12 | if is_method { |
13 | mut is_duplicate := type_sym.has_method(name) |
14 | // make sure this is a normal method and not an interface method |
15 | if type_sym.kind == .interface_ && is_duplicate { |
16 | - if type_sym.info is ast.Interface { |
17 | + if mut type_sym.info is ast.Interface { |
18 | // if the method is in info then its an interface method |
19 | is_duplicate = !type_sym.info.has_method(name) |
20 | } |
21 | } else if p.tok.kind in [.ne, .gt, .ge, .le] && p.peek_tok.kind == .lpar { |
22 | p.error_with_pos('cannot overload `!=`, `>`, `<=` and `>=` as they are auto generated from `==` and`<`', |
23 | p.tok.pos()) |
24 | + } else if p.tok.kind in [.plus_assign, .minus_assign, .div_assign, .mult_assign, .mod_assign] { |
25 | + extracted_op := match p.tok.kind { |
26 | + .plus_assign { '+' } |
27 | + .minus_assign { '-' } |
28 | + .div_assign { '/' } |
29 | + .mod_assign { '%' } |
30 | + .mult_assign { '*' } |
31 | + else { 'unknown op' } |
32 | + } |
33 | + if type_sym.has_method(extracted_op) { |
34 | + p.error('cannot overload `${p.tok.kind}`, operator is implicitly overloaded because the `${extracted_op}` operator is overloaded') |
35 | + } |
36 | + p.error('cannot overload `${p.tok.kind}`, overload `${extracted_op}` and `${p.tok.kind}` will be automatically generated') |
37 | } else { |
38 | p.error_with_pos('expecting method name', p.tok.pos()) |
39 | return ast.FnDecl{ |
40 | } |
41 | // Register |
42 | if is_method { |
43 | - mut type_sym := p.table.sym(rec.typ) |
44 | // Do not allow to modify / add methods to types from other modules |
45 | // arrays/maps dont belong to a module only their element types do |
46 | // we could also check if kind is .array, .array_fixed, .map instead of mod.len |
47 | |