mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: prohibit selective const imports (#10574)
This commit is contained in:
parent
02f4f635cf
commit
eb5afb7403
@ -117,6 +117,13 @@ pub fn new_checker(table &ast.Table, pref &pref.Preferences) &Checker {
|
||||
pub fn (mut c Checker) check(ast_file &ast.File) {
|
||||
c.change_current_file(ast_file)
|
||||
for i, ast_import in ast_file.imports {
|
||||
for sym in ast_import.syms {
|
||||
full_name := ast_import.mod + '.' + sym.name
|
||||
if full_name in c.const_names {
|
||||
c.error('cannot selectively import constant `$sym.name` from `$ast_import.mod`, import `$ast_import.mod` and use `$full_name` instead',
|
||||
sym.pos)
|
||||
}
|
||||
}
|
||||
for j in 0 .. i {
|
||||
if ast_import.mod == ast_file.imports[j].mod {
|
||||
c.error('`$ast_import.mod` was already imported on line ${
|
||||
|
3
vlib/v/checker/tests/selective_const_import.out
Normal file
3
vlib/v/checker/tests/selective_const_import.out
Normal file
@ -0,0 +1,3 @@
|
||||
vlib/v/checker/tests/selective_const_import.vv:1:15: error: cannot selectively import constant `second` from `time`, import `time` and use `time.second` instead
|
||||
1 | import time { second }
|
||||
| ~~~~~~
|
1
vlib/v/checker/tests/selective_const_import.vv
Normal file
1
vlib/v/checker/tests/selective_const_import.vv
Normal file
@ -0,0 +1 @@
|
||||
import time { second }
|
@ -1,6 +1,6 @@
|
||||
module main
|
||||
|
||||
import geometry { Line, Point, PointCond, Shape, module_name, point_str }
|
||||
import geometry { Line, Point, PointCond, Shape, point_str }
|
||||
|
||||
fn point_is(p Point, cond PointCond) bool {
|
||||
return cond(p)
|
||||
@ -39,10 +39,6 @@ fn test_imported_symbols_functions() {
|
||||
assert point_str(p0) == '20 40'
|
||||
}
|
||||
|
||||
fn test_imported_symbols_constants() {
|
||||
assert module_name == 'geometry'
|
||||
}
|
||||
|
||||
fn vertex_count(s Shape) int {
|
||||
return match s {
|
||||
.circle { 0 }
|
||||
|
Loading…
Reference in New Issue
Block a user