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:
parent
27b3303eeb
commit
77a1f5928f
@ -179,6 +179,12 @@ pub fn (mut c Checker) check(ast_file_ &ast.File) {
|
|||||||
if ast_import.mod == ast_file.imports[j].mod {
|
if ast_import.mod == ast_file.imports[j].mod {
|
||||||
c.error('`${ast_import.mod}` was already imported on line ${
|
c.error('`${ast_import.mod}` was already imported on line ${
|
||||||
ast_file.imports[j].mod_pos.line_nr + 1}', ast_import.mod_pos)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 := {
|
12
vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.vv
Executable file
12
vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.vv
Executable 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)
|
6
vlib/v/checker/tests/import_mod_as_import_duplicate_err.out
Executable file
6
vlib/v/checker/tests/import_mod_as_import_duplicate_err.out
Executable 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 := {
|
12
vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv
Normal file
12
vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv
Normal 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)
|
Loading…
Reference in New Issue
Block a user