parser: hot fix to handle `x = <-ch[i] or { }` (#7416)
parent
cd30dcc287
commit
8278af4ee8
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue