mirror of
https://github.com/vlang/v.git
synced 2025-09-18 11:56:57 -04:00
checker: revise logic for reporting import conflicts with module names (#24539)
This commit is contained in:
parent
140c7ea889
commit
299ebdff04
@ -239,16 +239,21 @@ pub fn (mut c Checker) check(mut ast_file ast.File) {
|
||||
sym.pos)
|
||||
}
|
||||
}
|
||||
|
||||
cmp_mod_name := if ast_import.mod != ast_import.alias && ast_import.alias != '_' {
|
||||
ast_import.alias
|
||||
} else {
|
||||
ast_import.mod
|
||||
}
|
||||
for j in 0 .. i {
|
||||
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_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)
|
||||
if cmp_mod_name == if ast_file.imports[j].mod != ast_file.imports[j].alias
|
||||
&& ast_file.imports[j].alias != '_' {
|
||||
ast_file.imports[j].alias
|
||||
} else {
|
||||
ast_file.imports[j].mod
|
||||
} {
|
||||
c.error('A module `${cmp_mod_name}` was already imported on line ${
|
||||
ast_file.imports[j].mod_pos.line_nr + 1}`.', ast_import.mod_pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.vv:2:19: error: `json` was already imported on line 1
|
||||
vlib/v/checker/tests/import_mod_as_import_alias_duplicate_err.vv:2:8: error: A module `json` was already imported on line 1`.
|
||||
1 | import json
|
||||
2 | import x.json2 as json
|
||||
| ~~~~
|
||||
| ~~~~~~~
|
||||
3 |
|
||||
4 | numbers := {
|
||||
|
@ -1,4 +1,4 @@
|
||||
vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv:2:8: error: `x.json2` was already imported as `json` on line 1
|
||||
vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv:2:8: error: A module `json` was already imported on line 1`.
|
||||
1 | import x.json2 as json
|
||||
2 | import json
|
||||
| ~~~~
|
||||
|
13
vlib/v/tests/import_order_1_test.v
Normal file
13
vlib/v/tests/import_order_1_test.v
Normal file
@ -0,0 +1,13 @@
|
||||
// NOTE: the order of these import statements is the opposite of the one in import_order_2_test.v,
|
||||
// but *both* should compile and work:
|
||||
import x.benchmark
|
||||
import benchmark as jj
|
||||
|
||||
fn test_runs() {
|
||||
mut b := jj.start()
|
||||
mut action := benchmark.setup(fn () ! {
|
||||
return error('no')
|
||||
})!
|
||||
action.run()
|
||||
b.measure('nothing')
|
||||
}
|
13
vlib/v/tests/import_order_2_test.v
Normal file
13
vlib/v/tests/import_order_2_test.v
Normal file
@ -0,0 +1,13 @@
|
||||
// NOTE: the order of these import statements is the opposite of the one in import_order_1_test.v,
|
||||
// but *both* should compile and work:
|
||||
import benchmark as jj
|
||||
import x.benchmark
|
||||
|
||||
fn test_runs() {
|
||||
mut b := jj.start()
|
||||
mut action := benchmark.setup(fn () ! {
|
||||
return error('no')
|
||||
})!
|
||||
action.run()
|
||||
b.measure('nothing')
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user