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

checker: check import duplicates

This commit is contained in:
yuyi 2020-04-30 15:33:12 +08:00 committed by GitHub
parent f6d74c8a37
commit c4f672454f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -48,6 +48,13 @@ pub fn new_checker(table &table.Table, pref &pref.Preferences) Checker {
pub fn (mut c Checker) check(ast_file ast.File) {
c.file = ast_file
for i, ast_import in ast_file.imports {
for j in 0..i {
if ast_import.mod == ast_file.imports[j].mod {
c.error('module name `$ast_import.mod` duplicate', ast_import.pos)
}
}
}
for stmt in ast_file.stmts {
c.stmt(stmt)
}

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/import_duplicate_err.v:2:8: error: module name `time` duplicate
1| import time
2| import time
~~~~
3| fn main() {
4| println(time.now().unix_time())

View File

@ -0,0 +1,5 @@
import time
import time
fn main() {
println(time.now().unix_time())
}