diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 9a03e61479..2998cc3395 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -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 { diff --git a/vlib/v/parser/tests/redeclaration_of_imported_fn.out b/vlib/v/parser/tests/redeclaration_of_imported_fn.out new file mode 100644 index 0000000000..1c02758ae5 --- /dev/null +++ b/vlib/v/parser/tests/redeclaration_of_imported_fn.out @@ -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() diff --git a/vlib/v/parser/tests/redeclaration_of_imported_fn.vv b/vlib/v/parser/tests/redeclaration_of_imported_fn.vv new file mode 100644 index 0000000000..45a3b5ad77 --- /dev/null +++ b/vlib/v/parser/tests/redeclaration_of_imported_fn.vv @@ -0,0 +1,5 @@ +import os { input } + +fn input() {} + +input()