mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
7d0a9186bb
commit
64eab72f4c
|
@ -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)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
123
|
16
vlib/v/checker/tests/globals_run/global_var_in_anon_fn.vv
Normal file
16
vlib/v/checker/tests/globals_run/global_var_in_anon_fn.vv
Normal file
|
@ -0,0 +1,16 @@
|
|||
module main
|
||||
|
||||
__global (
|
||||
number int
|
||||
)
|
||||
|
||||
fn init() {
|
||||
number = 123
|
||||
}
|
||||
|
||||
fn main() {
|
||||
f1 := fn() {
|
||||
println(number)
|
||||
}
|
||||
f1()
|
||||
}
|
Loading…
Reference in New Issue
Block a user