1
0
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:
shadowninja55 2021-06-25 07:27:58 -04:00 committed by GitHub
parent be8be3d319
commit 9b84faad6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View File

@ -267,13 +267,20 @@ 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 {
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 {
name = p.tok.kind.str() // op_to_fn_name()
if rec.typ == ast.void_type {

View 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()

View File

@ -0,0 +1,5 @@
import os { input }
fn input() {}
input()