1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: fix eval not used in match

This commit is contained in:
Alexander Medvednikov 2020-05-12 00:26:39 +02:00
parent 27d3800cc3
commit 712fd384ee
2 changed files with 4 additions and 1 deletions

View File

@ -166,7 +166,9 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
} }
branch_last_pos := p.tok.position() branch_last_pos := p.tok.position()
// p.warn('match block') // p.warn('match block')
p.inside_match_body = true
stmts := p.parse_block() stmts := p.parse_block()
p.inside_match_body = false
pos := token.Position{ pos := token.Position{
line_nr: branch_first_pos.line_nr line_nr: branch_first_pos.line_nr
pos: branch_first_pos.pos pos: branch_first_pos.pos

View File

@ -44,6 +44,7 @@ mut:
returns bool returns bool
inside_match bool // to separate `match A { }` from `Struct{}` inside_match bool // to separate `match A { }` from `Struct{}`
inside_match_case bool // to separate `match_expr { }` from `Struct{}` inside_match_case bool // to separate `match_expr { }` from `Struct{}`
inside_match_body bool // to fix eval not used TODO
inside_unsafe bool inside_unsafe bool
is_stmt_ident bool // true while the beginning of a statement is an ident/selector is_stmt_ident bool // true while the beginning of a statement is an ident/selector
expecting_type bool // `is Type`, expecting type expecting_type bool // `is Type`, expecting type
@ -485,7 +486,7 @@ pub fn (mut p Parser) stmt() ast.Stmt {
} }
} else if p.tok.kind == .name && p.peek_tok.kind == .name { } else if p.tok.kind == .name && p.peek_tok.kind == .name {
p.error_with_pos('unexpected name `$p.peek_tok.lit`', p.peek_tok.position()) p.error_with_pos('unexpected name `$p.peek_tok.lit`', p.peek_tok.position())
} else if p.tok.kind == .name && !p.inside_if_expr && !p.inside_match && !p.inside_or_expr && } else if p.tok.kind == .name && !p.inside_if_expr && !p.inside_match_body && !p.inside_or_expr &&
p.peek_tok.kind in [.rcbr, .eof] { p.peek_tok.kind in [.rcbr, .eof] {
p.error_with_pos('`$p.tok.lit` evaluated but not used', p.tok.position()) p.error_with_pos('`$p.tok.lit` evaluated but not used', p.tok.position())
} }