diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index a7cc6832d6..6bf877dffb 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -83,8 +83,11 @@ fn (mut p Parser) check_expr(precedence int) !ast.Expr { p.tok.pos()) } else if p.tok.kind == .question && p.peek_tok.kind == .amp { node = p.prefix_expr() - } else if p.inside_for_expr && p.tok.kind == .name && p.tok.lit[0].is_capital() - && p.peek_tok.kind == .lcbr && p.peek_token(2).kind in [.rcbr, .name] { + } else if p.inside_for_expr && p.tok.kind == .name && ((p.tok.lit[0].is_capital() + && p.peek_tok.kind == .lcbr && p.peek_token(2).kind in [.rcbr, .name]) + || (p.inside_array_lit && p.peek_tok.kind == .dot && p.peek_token(2).kind == .name + && p.peek_token(2).lit[0].is_capital() && p.peek_token(3).kind == .lcbr + && p.peek_token(4).kind in [.rcbr, .name])) { node = p.struct_init(p.mod + '.' + p.tok.lit, .normal, false) } else if p.is_generic_name() && p.peek_tok.kind == .lcbr && p.peek_token(2).kind == .rcbr && p.peek_token(2).line_nr == p.tok.line_nr { diff --git a/vlib/v/tests/structs/struct_init_with_mod_prefix_in_for_in_array_init_test.v b/vlib/v/tests/structs/struct_init_with_mod_prefix_in_for_in_array_init_test.v new file mode 100644 index 0000000000..60244c95c9 --- /dev/null +++ b/vlib/v/tests/structs/struct_init_with_mod_prefix_in_for_in_array_init_test.v @@ -0,0 +1,36 @@ +import v.ast + +fn test_main() { + for idx, s in [ast.Struct{ + scoped_name: '1' + }, ast.Struct{ + embeds: [ast.Type(2), 3] + }, ast.Struct{ + is_typedef: true + is_union: true + is_heap: true + }, ast.Struct{ + is_minify: ast.Struct{ + is_anon: true + }.is_generic + is_shared: true + }, ast.Struct{ + has_option: true + }] { + println('${idx} ${s}') + if idx == 0 { + assert s.scoped_name == '1' + } else if idx == 1 { + assert s.embeds == [ast.Type(2), 3] + } else if idx == 2 { + assert s.is_typedef == true + assert s.is_union == true + assert s.is_heap == true + } else if idx == 3 { + assert s.is_minify == false + assert s.is_shared == true + } else if idx == 4 { + assert s.has_option == true + } + } +}