Skip to content

Commit eaf005e

Browse files
authored
parser: add duplicate import symbol detect (fix #25185) (#25187)
1 parent 0799781 commit eaf005e

6 files changed

Lines changed: 15 additions & 18 deletions

‎vlib/v/fmt/tests/import_duplicate_input.vv‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎vlib/v/parser/module.v‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ fn (mut p Parser) import_syms(mut parent ast.Import) {
310310
for p.tok.kind == .name {
311311
pos := p.tok.pos()
312312
alias := p.check_name()
313+
if alias in p.imported_symbols {
314+
p.error_with_pos('cannot register symbol `${alias}`, it was already imported',
315+
pos)
316+
return
317+
}
313318
p.imported_symbols[alias] = parent.mod + '.' + alias
314319
// so we can work with this in fmt+checker
315320
parent.syms << ast.ImportSymbol{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vlib/v/parser/tests/module_import_same_symbol2_err.vv:1:20: error: cannot register symbol `max`, it was already imported
2+
1 | import math { max, max }
3+
| ~~~
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import math { max, max }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vlib/v/parser/tests/module_import_same_symbol_err.vv:2:17: error: cannot register symbol `max`, it was already imported
2+
1 | import math { max }
3+
2 | import arrays { max }
4+
| ~~~
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import math { max }
2+
import arrays { max }

0 commit comments

Comments
 (0)