1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: include import aliases when checking for import duplicates (#18450)

This commit is contained in:
Turiiya 2023-06-15 01:06:44 +02:00 committed by GitHub
parent 27b3303eeb
commit 77a1f5928f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 0 deletions

View File

@ -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)
}
}
}

View File

@ -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 := {

View File

@ -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)

View File

@ -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 := {

View File

@ -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)