v.parser: prohibit redeclaration of imported functions (#10564)
parent
be8be3d319
commit
9b84faad6f
|
@ -267,11 +267,18 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cannot redefine buildin function
|
if !p.pref.is_fmt {
|
||||||
if !is_method && !p.builtin_mod && name in builtin_functions {
|
if !is_method && !p.builtin_mod && name in builtin_functions {
|
||||||
p.error_with_pos('cannot redefine builtin function `$name`', name_pos)
|
p.error_with_pos('cannot redefine builtin function `$name`', name_pos)
|
||||||
return ast.FnDecl{
|
return ast.FnDecl{
|
||||||
scope: 0
|
scope: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if name in p.imported_symbols {
|
||||||
|
p.error_with_pos('cannot redefine imported function `$name`', name_pos)
|
||||||
|
return ast.FnDecl{
|
||||||
|
scope: 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else 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 {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/parser/tests/redeclaration_of_imported_fn.vv:3:4: error: cannot redefine imported function `input`
|
||||||
|
1 | import os { input }
|
||||||
|
2 |
|
||||||
|
3 | fn input() {}
|
||||||
|
| ~~~~~
|
||||||
|
4 |
|
||||||
|
5 | input()
|
|
@ -0,0 +1,5 @@
|
||||||
|
import os { input }
|
||||||
|
|
||||||
|
fn input() {}
|
||||||
|
|
||||||
|
input()
|
Loading…
Reference in New Issue