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

checker: fix anon fn using global variable (fix #15004) (#15008)

This commit is contained in:
yuyi 2022-07-10 17:43:50 +08:00 committed by GitHub
parent 7d0a9186bb
commit 64eab72f4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -2771,6 +2771,14 @@ pub fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
}
if mut obj := c.file.global_scope.find(name) {
match mut obj {
ast.GlobalField {
node.kind = .global
node.info = ast.IdentVar{
typ: obj.typ
}
node.obj = obj
return obj.typ
}
ast.ConstField {
if !(obj.is_pub || obj.mod == c.mod || c.pref.is_test) {
c.error('constant `$obj.name` is private', node.pos)

View File

@ -0,0 +1 @@
123

View File

@ -0,0 +1,16 @@
module main
__global (
number int
)
fn init() {
number = 123
}
fn main() {
f1 := fn() {
println(number)
}
f1()
}