diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 029da8f25f3d6f..b601c161fae75c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -179,6 +179,12 @@ pub fn (mut c Checker) check(ast_file_ &ast.File) { if ast_import.mod == ast_file.imports[j].mod { c.error('`${ast_import.mod}` was already imported on line ${ ast_file.imports[j].mod_pos.line_nr + 1}', ast_import.mod_pos) + } else if ast_import.mod == ast_file.imports[j].alias { + c.error('`${ast_file.imports[j].mod}` was already imported as `${ast_import.alias}` on line ${ + ast_file.imports[j].mod_pos.line_nr + 1}', ast_import.mod_pos) + } else if ast_import.alias == ast_file.imports[j].alias { + c.error('`${ast_file.imports[j].mod}` was already imported on line ${ + ast_file.imports[j].alias_pos.line_nr + 1}', ast_import.alias_pos) } } } diff --git a/vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.out b/vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.out new file mode 100644 index 00000000000000..976fb4b9e1fb6e --- /dev/null +++ b/vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.vv:2:19: error: `json` was already imported on line 1 + 1 | import json + 2 | import x.json2 as json + | ~~~~ + 3 | + 4 | numbers := { diff --git a/vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.vv b/vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.vv new file mode 100755 index 00000000000000..5f1285c919eaef --- /dev/null +++ b/vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.vv @@ -0,0 +1,12 @@ +import json +import x.json2 as json + +numbers := { + 'one': 1 + 'two': 2 + 'three': 3 + 'four': 4 +} + +out := json.encode(numbers) +println(out) diff --git a/vlib/v/checker/tests/import_mod_as_import_duplicate_err.out b/vlib/v/checker/tests/import_mod_as_import_duplicate_err.out new file mode 100755 index 00000000000000..e1aeede3481cb3 --- /dev/null +++ b/vlib/v/checker/tests/import_mod_as_import_duplicate_err.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv:2:8: error: `x.json2` was already imported as `json` on line 1 + 1 | import x.json2 as json + 2 | import json + | ~~~~ + 3 | + 4 | numbers := { \ No newline at end of file diff --git a/vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv b/vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv new file mode 100644 index 00000000000000..e86992b61ede3e --- /dev/null +++ b/vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv @@ -0,0 +1,12 @@ +import x.json2 as json +import json + +numbers := { + 'one': 1 + 'two': 2 + 'three': 3 + 'four': 4 +} + +out := json.encode(numbers) +println(out)