From af75789bbf6060e1cb1527e096ea8287e67fc13f Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 10 Sep 2021 20:31:09 +0800 Subject: [PATCH] parser: fix reference var followed by block expr (#11456) --- vlib/v/parser/parser.v | 2 +- vlib/v/tests/reference_var_followed_block_expr.v | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/reference_var_followed_block_expr.v diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index ca15e76913..352efea2c7 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2170,7 +2170,7 @@ pub fn (mut p Parser) name_expr() ast.Expr { } else if (p.peek_tok.kind == .lcbr || (p.peek_tok.kind == .lt && lit0_is_capital)) && (!p.inside_match || (p.inside_select && prev_tok_kind == .arrow && lit0_is_capital)) && !p.inside_match_case && (!p.inside_if || p.inside_select) - && (!p.inside_for || p.inside_select) { // && (p.tok.lit[0].is_capital() || p.builtin_mod) { + && (!p.inside_for || p.inside_select) && !known_var { // && (p.tok.lit[0].is_capital() || p.builtin_mod) { // map.v has struct literal: map{field: expr} if p.peek_tok.kind == .lcbr && !(p.builtin_mod && p.file_base in ['map.v', 'map_d_gcboehm_opt.v']) && p.tok.lit == 'map' { diff --git a/vlib/v/tests/reference_var_followed_block_expr.v b/vlib/v/tests/reference_var_followed_block_expr.v new file mode 100644 index 0000000000..9f285b1c42 --- /dev/null +++ b/vlib/v/tests/reference_var_followed_block_expr.v @@ -0,0 +1,8 @@ +fn test_reference_var_followed_block_expr() { + mut b := [5, 6, 7] + mut c := &b + { + } + println(c) + assert '$c' == '&[5, 6, 7]' +}