From 13b11a415562bb2355807613bd0bac4aa0a04021 Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Fri, 8 May 2020 19:09:40 +0800 Subject: [PATCH] parser: fix struct attribute for array struct field --- vlib/v/parser/parse_type.v | 6 +++++- vlib/v/tests/struct_test.v | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 6f02e5061a..fceeccca0a 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -20,7 +20,11 @@ pub fn (mut p Parser) parse_array_type() table.Type { p.check(.rsbr) elem_type := p.parse_type() mut nr_dims := 1 - for p.tok.kind == .lsbr { + + // detect attr + not_attr := p.peek_tok.kind != .name && p.peek_tok2.kind !in [.semicolon, .rsbr] + + for p.tok.kind == .lsbr && not_attr { p.next() p.check(.rsbr) nr_dims++ diff --git a/vlib/v/tests/struct_test.v b/vlib/v/tests/struct_test.v index 468bdf6d5c..f6695f2097 100644 --- a/vlib/v/tests/struct_test.v +++ b/vlib/v/tests/struct_test.v @@ -17,6 +17,12 @@ mut: num int } +struct Lol { + b []string [json:lol] + c string [json:cc] + d int +} + struct User { name string age int