mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.parser: prohibit redeclaration of imported functions (#10564)
This commit is contained in:
parent
be8be3d319
commit
9b84faad6f
@ -267,11 +267,18 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||
}
|
||||
}
|
||||
}
|
||||
// cannot redefine buildin function
|
||||
if !is_method && !p.builtin_mod && name in builtin_functions {
|
||||
p.error_with_pos('cannot redefine builtin function `$name`', name_pos)
|
||||
return ast.FnDecl{
|
||||
scope: 0
|
||||
if !p.pref.is_fmt {
|
||||
if !is_method && !p.builtin_mod && name in builtin_functions {
|
||||
p.error_with_pos('cannot redefine builtin function `$name`', name_pos)
|
||||
return ast.FnDecl{
|
||||
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 {
|
||||
|
7
vlib/v/parser/tests/redeclaration_of_imported_fn.out
Normal file
7
vlib/v/parser/tests/redeclaration_of_imported_fn.out
Normal file
@ -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()
|
5
vlib/v/parser/tests/redeclaration_of_imported_fn.vv
Normal file
5
vlib/v/parser/tests/redeclaration_of_imported_fn.vv
Normal file
@ -0,0 +1,5 @@
|
||||
import os { input }
|
||||
|
||||
fn input() {}
|
||||
|
||||
input()
|
Loading…
Reference in New Issue
Block a user