Skip to content

Commit

Permalink
checker: include import aliases when checking for import duplicates (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Jun 14, 2023
1 parent 27b3303 commit 77a1f59
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vlib/v/checker/checker.v
Expand Up @@ -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)
}
}
}
Expand Down
@@ -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 changes: 12 additions & 0 deletions 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)
6 changes: 6 additions & 0 deletions 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 := {
12 changes: 12 additions & 0 deletions 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)

0 comments on commit 77a1f59

Please sign in to comment.