From c72bf0e1b1586a6b2be4f739463641d9e1dee941 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 13 Dec 2019 20:28:28 +0300 Subject: [PATCH] global access modifier --- vlib/compiler/struct.v | 14 ++++++++++++-- vlib/compiler/tests/struct_test.v | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/vlib/compiler/struct.v b/vlib/compiler/struct.v index f8cd443b66..dd8264b86b 100644 --- a/vlib/compiler/struct.v +++ b/vlib/compiler/struct.v @@ -161,6 +161,17 @@ fn (p mut Parser) struct_decl() { p.fmt_inc() p.fgen_nl() } + else if p.tok == .key_global { + new_access_mod = .global + if new_access_mod in used { + p.error('structs can only have one `__global:`, all global fields have to be grouped') + } + p.fmt_dec() + p.check(.key_global) + p.check(.colon) + p.fmt_inc() + p.fgen_nl() + } if new_access_mod != access_mod { used << new_access_mod } @@ -246,9 +257,8 @@ fn (p mut Parser) struct_decl() { if attr == 'raw' && field_type != 'string' { p.error('struct field with attribute "raw" should be of type "string" but got "$field_type"') } - did_gen_something = true - is_mut := access_mod in [.private_mut, .public_mut] + is_mut := access_mod in [.private_mut, .public_mut, .global] if p.first_pass() { p.table.add_field(typ.name, field_name, field_type, is_mut, attr, access_mod) diff --git a/vlib/compiler/tests/struct_test.v b/vlib/compiler/tests/struct_test.v index f0931b7471..4e7eccdb86 100644 --- a/vlib/compiler/tests/struct_test.v +++ b/vlib/compiler/tests/struct_test.v @@ -163,7 +163,7 @@ pub: d int // public immmutable (readonly) pub mut: e int // public, but mutable only in parent module -//__global: +__global: f int // public and mutable both inside and outside parent module }