parser: hot fix to handle `x = <-ch[i] or { }` (#7416)

pull/7415/head^2
Uwe Krüger 2020-12-19 21:44:16 +01:00 committed by GitHub
parent cd30dcc287
commit 8278af4ee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -38,6 +38,7 @@ mut:
inside_for bool inside_for bool
inside_fn bool inside_fn bool
inside_str_interp bool inside_str_interp bool
or_is_handled bool // ignore `or` in this expression
builtin_mod bool // are we in the `builtin` module? builtin_mod bool // are we in the `builtin` module?
mod string // current module name mod string // current module name
attrs []table.Attr // attributes before next decl stmt 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()) pos := start_pos.extend(p.tok.position())
p.check(.rsbr) p.check(.rsbr)
// a[i] or { ... } // 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 was_inside_or_expr := p.inside_or_expr
mut or_pos := p.tok.position() mut or_pos := p.tok.position()
p.next() p.next()

View File

@ -371,6 +371,7 @@ fn (mut p Parser) prefix_expr() ast.PrefixExpr {
p.is_amp = true p.is_amp = true
} }
if op == .arrow { if op == .arrow {
p.or_is_handled = true
p.register_auto_import('sync') p.register_auto_import('sync')
} }
// if op == .mul && !p.inside_unsafe { // if op == .mul && !p.inside_unsafe {
@ -411,6 +412,7 @@ fn (mut p Parser) prefix_expr() ast.PrefixExpr {
p.next() p.next()
or_kind = .propagate or_kind = .propagate
} }
p.or_is_handled = false
} }
return ast.PrefixExpr{ return ast.PrefixExpr{
op: op op: op