mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
checker: turn warning for var and param module name duplicates into error (#19645)
This commit is contained in:
parent
a63f3e6f77
commit
eab77ccb9a
7 changed files with 13 additions and 19 deletions
|
@ -46,18 +46,18 @@ pub fn new_log_as_logger() &Logger {
|
||||||
|
|
||||||
fn test_log_mutable() {
|
fn test_log_mutable() {
|
||||||
println(@FN + ' start')
|
println(@FN + ' start')
|
||||||
mut log := Log{}
|
mut l := Log{}
|
||||||
log.set_level(.info)
|
l.set_level(.info)
|
||||||
log_mutable_statements(mut log)
|
log_mutable_statements(mut l)
|
||||||
assert true
|
assert true
|
||||||
println(@FN + ' end')
|
println(@FN + ' end')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_log_mutable_reference() {
|
fn test_log_mutable_reference() {
|
||||||
println(@FN + ' start')
|
println(@FN + ' start')
|
||||||
mut log := new_log()
|
mut l := new_log()
|
||||||
assert typeof(log).name == '&log.Log'
|
assert typeof(l).name == '&log.Log'
|
||||||
t := spawn log_mutable_statements(mut log)
|
t := spawn log_mutable_statements(mut l)
|
||||||
t.wait()
|
t.wait()
|
||||||
assert true
|
assert true
|
||||||
println(@FN + ' end')
|
println(@FN + ' end')
|
||||||
|
|
|
@ -375,8 +375,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if left.name == left.mod && left.name != 'main' {
|
if left.name == left.mod && left.name != 'main' {
|
||||||
c.add_error_detail('Module name duplicates will become errors after 2023/10/31.')
|
c.error('duplicate of a module name `${left.name}`', left.pos)
|
||||||
c.note('duplicate of a module name `${left.name}`', left.pos)
|
|
||||||
}
|
}
|
||||||
// Check if variable name is already registered as imported module symbol
|
// Check if variable name is already registered as imported module symbol
|
||||||
if c.check_import_sym_conflict(left.name) {
|
if c.check_import_sym_conflict(left.name) {
|
||||||
|
|
|
@ -1692,8 +1692,7 @@ fn (mut c Checker) const_decl(mut node ast.ConstDecl) {
|
||||||
...field.pos
|
...field.pos
|
||||||
len: util.no_cur_mod(field.name, c.mod).len
|
len: util.no_cur_mod(field.name, c.mod).len
|
||||||
}
|
}
|
||||||
c.add_error_detail('Module name duplicates will become errors after 2023/10/31.')
|
c.error('duplicate of a module name `${field.name}`', name_pos)
|
||||||
c.note('duplicate of a module name `${field.name}`', name_pos)
|
|
||||||
}
|
}
|
||||||
c.const_names << field.name
|
c.const_names << field.name
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,8 +267,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if param.name == node.mod && param.name != 'main' {
|
if param.name == node.mod && param.name != 'main' {
|
||||||
c.add_error_detail('Module name duplicates will become errors after 2023/10/31.')
|
c.error('duplicate of a module name `${param.name}`', param.pos)
|
||||||
c.note('duplicate of a module name `${param.name}`', param.pos)
|
|
||||||
}
|
}
|
||||||
// Check if parameter name is already registered as imported module symbol
|
// Check if parameter name is already registered as imported module symbol
|
||||||
if c.check_import_sym_conflict(param.name) {
|
if c.check_import_sym_conflict(param.name) {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
vlib/v/checker/tests/mod_name_duplicate_const_err.vv:3:7: notice: duplicate of a module name `foo.foo`
|
vlib/v/checker/tests/mod_name_duplicate_const_err.vv:3:7: error: duplicate of a module name `foo.foo`
|
||||||
1 | module foo
|
1 | module foo
|
||||||
2 |
|
2 |
|
||||||
3 | const foo = 'bar'
|
3 | const foo = 'bar'
|
||||||
| ~~~
|
| ~~~
|
||||||
Details: Module name duplicates will become errors after 2023/10/31.
|
|
||||||
vlib/v/checker/tests/mod_name_duplicate_const_err.vv:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
|
vlib/v/checker/tests/mod_name_duplicate_const_err.vv:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
|
||||||
1 | module foo
|
1 | module foo
|
||||||
| ^
|
| ^
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
vlib/v/checker/tests/mod_name_duplicate_param_err.vv:3:8: notice: duplicate of a module name `foo`
|
vlib/v/checker/tests/mod_name_duplicate_param_err.vv:3:8: error: duplicate of a module name `foo`
|
||||||
1 | module foo
|
1 | module foo
|
||||||
2 |
|
2 |
|
||||||
3 | fn bar(foo string) {
|
3 | fn bar(foo string) {
|
||||||
| ~~~
|
| ~~~
|
||||||
4 | println(foo)
|
4 | println(foo)
|
||||||
5 | }
|
5 | }
|
||||||
Details: Module name duplicates will become errors after 2023/10/31.
|
|
||||||
vlib/v/checker/tests/mod_name_duplicate_param_err.vv:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
|
vlib/v/checker/tests/mod_name_duplicate_param_err.vv:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
|
||||||
1 | module foo
|
1 | module foo
|
||||||
| ^
|
| ^
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
vlib/v/checker/tests/mod_name_duplicate_var_err.vv:4:2: notice: duplicate of a module name `foo`
|
vlib/v/checker/tests/mod_name_duplicate_var_err.vv:4:2: error: duplicate of a module name `foo`
|
||||||
2 |
|
2 |
|
||||||
3 | fn bar() {
|
3 | fn bar() {
|
||||||
4 | foo := 'bar'
|
4 | foo := 'bar'
|
||||||
| ~~~
|
| ~~~
|
||||||
5 | println(foo)
|
5 | println(foo)
|
||||||
6 | }
|
6 | }
|
||||||
Details: Module name duplicates will become errors after 2023/10/31.
|
|
||||||
vlib/v/checker/tests/mod_name_duplicate_var_err.vv:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
|
vlib/v/checker/tests/mod_name_duplicate_var_err.vv:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
|
||||||
1 | module foo
|
1 | module foo
|
||||||
| ^
|
| ^
|
||||||
2 |
|
2 |
|
||||||
3 | fn bar() {
|
3 | fn bar() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue