1
0
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:
shove 2022-09-08 00:06:45 +08:00 committed by GitHub
parent 7672725204
commit a75a12ec1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -2739,6 +2739,7 @@ pub fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
if mut obj := node.scope.find(node.name) {
match mut obj {
ast.GlobalField {
if node.mod == '' {
node.kind = .global
node.info = ast.IdentVar{
typ: obj.typ
@ -2746,6 +2747,7 @@ pub fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
node.obj = obj
return obj.typ
}
}
ast.Var {
// inside vweb tmpl ident positions are meaningless, use the position of the comptime call.
// if the variable is declared before the comptime call then we can assume all is well.

View 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
}