From 8a38bc23247410b31a9b8d21d2d4f47a43f1c996 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Sun, 2 Oct 2022 13:20:16 +0530 Subject: [PATCH] fmt: keep `volatile` qualifier in global declarations (#15947) --- vlib/v/fmt/fmt.v | 3 +++ vlib/v/fmt/tests/global_keep.vv | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 865f4243b8..f45d7419ec 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1103,6 +1103,9 @@ pub fn (mut f Fmt) global_decl(node ast.GlobalDecl) { } for field in node.fields { f.comments(field.comments, inline: true) + if field.is_volatile { + f.write('volatile ') + } f.write('$field.name ') f.write(strings.repeat(` `, max - field.name.len)) if field.has_expr { diff --git a/vlib/v/fmt/tests/global_keep.vv b/vlib/v/fmt/tests/global_keep.vv index e809f3d2fe..a16bcb3db4 100644 --- a/vlib/v/fmt/tests/global_keep.vv +++ b/vlib/v/fmt/tests/global_keep.vv @@ -1,3 +1,7 @@ +struct TestInt { + i int +} + __global x = bool(true) __global y f32 __global () @@ -6,5 +10,8 @@ __global ( foo = int(5) ) __global ( - a int + a int + volatile test_int = TestInt{ + i: 0 + } )