parser: add duplicate import symbol detect (fix #25185) (#25187)
Some checks are pending
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run

This commit is contained in:
kbkpbot 2025-08-29 18:31:59 +08:00 committed by GitHub
parent 07997816d9
commit eaf005e29f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 15 additions and 18 deletions

View file

@ -1,18 +0,0 @@
import math
import os
import math
// keep comment
import gg
import gg { MouseButton }
import time { Duration }
import time { Duration }
import math.complex { Complex }
import math.complex { Complex }
const mypi = math.pi
const mb = MouseButton{}
const complex = Complex{}
fn main() {
println(os.path_separator)
}

View file

@ -310,6 +310,11 @@ fn (mut p Parser) import_syms(mut parent ast.Import) {
for p.tok.kind == .name { for p.tok.kind == .name {
pos := p.tok.pos() pos := p.tok.pos()
alias := p.check_name() alias := p.check_name()
if alias in p.imported_symbols {
p.error_with_pos('cannot register symbol `${alias}`, it was already imported',
pos)
return
}
p.imported_symbols[alias] = parent.mod + '.' + alias p.imported_symbols[alias] = parent.mod + '.' + alias
// so we can work with this in fmt+checker // so we can work with this in fmt+checker
parent.syms << ast.ImportSymbol{ parent.syms << ast.ImportSymbol{

View file

@ -0,0 +1,3 @@
vlib/v/parser/tests/module_import_same_symbol2_err.vv:1:20: error: cannot register symbol `max`, it was already imported
1 | import math { max, max }
| ~~~

View file

@ -0,0 +1 @@
import math { max, max }

View file

@ -0,0 +1,4 @@
vlib/v/parser/tests/module_import_same_symbol_err.vv:2:17: error: cannot register symbol `max`, it was already imported
1 | import math { max }
2 | import arrays { max }
| ~~~

View file

@ -0,0 +1,2 @@
import math { max }
import arrays { max }