From 80d936adc1ef6a8c0415d634b8728624fe4b1d06 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Thu, 30 Jan 2020 11:27:13 +1100 Subject: [PATCH] fix attributes on public structs & enums --- vlib/compiler/aparser.v | 8 ++++--- vlib/compiler/tests/attribute_test.v | 33 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 vlib/compiler/tests/attribute_test.v diff --git a/vlib/compiler/aparser.v b/vlib/compiler/aparser.v index c75abbd6b2..485cd9267d 100644 --- a/vlib/compiler/aparser.v +++ b/vlib/compiler/aparser.v @@ -3071,17 +3071,19 @@ fn (p mut Parser) attribute() { } p.check(.rsbr) p.fgen_nl() - if p.tok == .key_fn || (p.tok == .key_pub && p.peek() == .key_fn) { + is_pub := p.tok == .key_pub + peek := p.peek() + if p.tok == .key_fn || (is_pub && peek == .key_fn) { p.fn_decl() p.attr = '' return } - else if p.tok == .key_struct { + else if p.tok == .key_struct || (is_pub && peek == .key_struct) { p.struct_decl([]) p.attr = '' return } - else if p.tok == .key_enum { + else if p.tok == .key_enum || (is_pub && peek == .key_enum) { p.enum_decl(false) p.attr = '' return diff --git a/vlib/compiler/tests/attribute_test.v b/vlib/compiler/tests/attribute_test.v new file mode 100644 index 0000000000..f16984f7f3 --- /dev/null +++ b/vlib/compiler/tests/attribute_test.v @@ -0,0 +1,33 @@ +[testing] +struct StructAttrTest { + foo string + bar int +} + +[testing] +pub struct PubStructAttrTest { + foo string + bar int +} + +[testing] +enum EnumAttrTest { + one + two +} + +[testing] +pub enum PubEnumAttrTest { + one + two +} + +[testing] +fn test_fn_attribte() { + assert true +} + +[testing] +pub fn test_pub_fn_attribte() { + assert true +} \ No newline at end of file