From 9ab1d17cbc5d9d4fffb609396f8cc7a3eacf0062 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Fri, 5 Feb 2021 16:46:43 +0100 Subject: [PATCH] fmt: keep __global in struct declarations (#8584) --- vlib/v/ast/ast.v | 1 + vlib/v/fmt/fmt.v | 2 ++ vlib/v/fmt/tests/struct_decl_keep.vv | 5 +++++ vlib/v/parser/struct.v | 1 + 4 files changed, 9 insertions(+) create mode 100644 vlib/v/fmt/tests/struct_decl_keep.vv diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index cafb872151..252d9a2e22 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -201,6 +201,7 @@ pub: mut_pos int // mut: pub_pos int // pub: pub_mut_pos int // pub mut: + global_pos int // __global: module_pos int // module: language table.Language is_union bool diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index ff0b403630..0225f4f7e7 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -687,6 +687,8 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) { f.writeln('pub:') } else if i == node.pub_mut_pos { f.writeln('pub mut:') + } else if i == node.global_pos { + f.writeln('__global:') } else if i == node.module_pos { f.writeln('module:') } diff --git a/vlib/v/fmt/tests/struct_decl_keep.vv b/vlib/v/fmt/tests/struct_decl_keep.vv new file mode 100644 index 0000000000..cb2de8c315 --- /dev/null +++ b/vlib/v/fmt/tests/struct_decl_keep.vv @@ -0,0 +1,5 @@ +struct Foo { + a int +__global: + g string +} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 60a811e2a6..f0e8f7bd46 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -323,6 +323,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { mut_pos: mut_pos - embeds.len pub_pos: pub_pos - embeds.len pub_mut_pos: pub_mut_pos - embeds.len + global_pos: global_pos - embeds.len module_pos: module_pos - embeds.len language: language is_union: is_union