diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 41f22e8b2e..df54cf5da5 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -38,6 +38,7 @@ mut: inside_for bool inside_fn bool inside_str_interp bool + or_is_handled bool // ignore `or` in this expression builtin_mod bool // are we in the `builtin` module? mod string // current module name attrs []table.Attr // attributes before next decl stmt @@ -1327,7 +1328,7 @@ fn (mut p Parser) index_expr(left ast.Expr) ast.IndexExpr { pos := start_pos.extend(p.tok.position()) p.check(.rsbr) // a[i] or { ... } - if p.tok.kind == .key_orelse { + if p.tok.kind == .key_orelse && !p.or_is_handled { was_inside_or_expr := p.inside_or_expr mut or_pos := p.tok.position() p.next() diff --git a/vlib/v/parser/pratt.v b/vlib/v/parser/pratt.v index debe374b27..aeab8be61a 100644 --- a/vlib/v/parser/pratt.v +++ b/vlib/v/parser/pratt.v @@ -371,6 +371,7 @@ fn (mut p Parser) prefix_expr() ast.PrefixExpr { p.is_amp = true } if op == .arrow { + p.or_is_handled = true p.register_auto_import('sync') } // if op == .mul && !p.inside_unsafe { @@ -411,6 +412,7 @@ fn (mut p Parser) prefix_expr() ast.PrefixExpr { p.next() or_kind = .propagate } + p.or_is_handled = false } return ast.PrefixExpr{ op: op