1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: check for name conflicts between const and __global variables (fix #15668) (#15669)

This commit is contained in:
shove 2022-09-05 23:58:30 +08:00 committed by GitHub
parent 6fd22531a9
commit 862d91ed0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -1656,6 +1656,9 @@ fn (mut c Checker) global_decl(mut node ast.GlobalDecl) {
if field.name in c.global_names {
c.error('duplicate global `$field.name`', field.pos)
}
if '${c.mod}.$field.name' in c.const_names {
c.error('duplicate global and const `$field.name`', field.pos)
}
sym := c.table.sym(field.typ)
if sym.kind == .placeholder {
c.error('unknown type `$sym.name`', field.typ_pos)

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/globals/name_conflict_with_const.vv:6:2: error: duplicate global and const `foo`
4 |
5 | __global (
6 | foo = 123
| ~~~
7 | )

View File

@ -0,0 +1,7 @@
const (
foo = 'abc'
)
__global (
foo = 123
)