mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix const variable type error when global variable with the same name exists (fix #15686) (#15689)
This commit is contained in:
parent
7672725204
commit
a75a12ec1e
@ -2739,12 +2739,14 @@ pub fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
|
|||||||
if mut obj := node.scope.find(node.name) {
|
if mut obj := node.scope.find(node.name) {
|
||||||
match mut obj {
|
match mut obj {
|
||||||
ast.GlobalField {
|
ast.GlobalField {
|
||||||
node.kind = .global
|
if node.mod == '' {
|
||||||
node.info = ast.IdentVar{
|
node.kind = .global
|
||||||
typ: obj.typ
|
node.info = ast.IdentVar{
|
||||||
|
typ: obj.typ
|
||||||
|
}
|
||||||
|
node.obj = obj
|
||||||
|
return obj.typ
|
||||||
}
|
}
|
||||||
node.obj = obj
|
|
||||||
return obj.typ
|
|
||||||
}
|
}
|
||||||
ast.Var {
|
ast.Var {
|
||||||
// inside vweb tmpl ident positions are meaningless, use the position of the comptime call.
|
// inside vweb tmpl ident positions are meaningless, use the position of the comptime call.
|
||||||
|
11
vlib/v/tests/const_and_global_with_same_name_test.v
Normal file
11
vlib/v/tests/const_and_global_with_same_name_test.v
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[has_globals]
|
||||||
|
module main
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
__global seconds_per_minute = 'sixty'
|
||||||
|
|
||||||
|
fn test_const_and_globals_with_the_same_name_in_different_modules_do_not_conflict() {
|
||||||
|
assert seconds_per_minute == 'sixty'
|
||||||
|
assert time.seconds_per_minute == 60
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user