parser: fix reference var followed by block expr (#11456)

pull/11459/head
yuyi 2021-09-10 20:31:09 +08:00 committed by GitHub
parent 91c6eeeae5
commit af75789bbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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' {

View File

@ -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]'
}