mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
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
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:
parent
07997816d9
commit
eaf005e29f
6 changed files with 15 additions and 18 deletions
|
@ -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)
|
||||
}
|
|
@ -310,6 +310,11 @@ fn (mut p Parser) import_syms(mut parent ast.Import) {
|
|||
for p.tok.kind == .name {
|
||||
pos := p.tok.pos()
|
||||
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
|
||||
// so we can work with this in fmt+checker
|
||||
parent.syms << ast.ImportSymbol{
|
||||
|
|
3
vlib/v/parser/tests/module_import_same_symbol2_err.out
Normal file
3
vlib/v/parser/tests/module_import_same_symbol2_err.out
Normal 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 }
|
||||
| ~~~
|
1
vlib/v/parser/tests/module_import_same_symbol2_err.vv
Normal file
1
vlib/v/parser/tests/module_import_same_symbol2_err.vv
Normal file
|
@ -0,0 +1 @@
|
|||
import math { max, max }
|
4
vlib/v/parser/tests/module_import_same_symbol_err.out
Normal file
4
vlib/v/parser/tests/module_import_same_symbol_err.out
Normal 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 }
|
||||
| ~~~
|
2
vlib/v/parser/tests/module_import_same_symbol_err.vv
Normal file
2
vlib/v/parser/tests/module_import_same_symbol_err.vv
Normal file
|
@ -0,0 +1,2 @@
|
|||
import math { max }
|
||||
import arrays { max }
|
Loading…
Add table
Add a link
Reference in a new issue