mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix a match error
This commit is contained in:
parent
caed4aad58
commit
93b942de46
7
vlib/v/checker/tests/inout/match_err.out
Normal file
7
vlib/v/checker/tests/inout/match_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/inout/match_err.v:4:15: error: undefined: `Asd`
|
||||
2|
|
||||
3| fn main() {
|
||||
4| res := match Asd {
|
||||
~~~
|
||||
5| 1 { 'foo' }
|
||||
6| 2 { 'test' }
|
9
vlib/v/checker/tests/inout/match_err.vv
Normal file
9
vlib/v/checker/tests/inout/match_err.vv
Normal file
@ -0,0 +1,9 @@
|
||||
type Asd = int
|
||||
|
||||
fn main() {
|
||||
res := match Asd {
|
||||
1 { 'foo' }
|
||||
2 { 'test' }
|
||||
else { '' }
|
||||
}
|
||||
}
|
@ -35,6 +35,7 @@ mut:
|
||||
ast_imports []ast.Import
|
||||
is_amp bool
|
||||
returns bool
|
||||
inside_match bool // to separate `match A { }` from `Struct{}`
|
||||
inside_match_case bool // to separate `match_expr { }` from `Struct{}`
|
||||
is_stmt_ident bool // true while the beginning of a statement is an ident/selector
|
||||
}
|
||||
@ -691,7 +692,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
||||
node = x
|
||||
}
|
||||
} else if p.peek_tok.kind == .lcbr && (p.tok.lit[0].is_capital() || is_c || (p.builtin_mod &&
|
||||
p.tok.lit in table.builtin_type_names)) && !p.inside_match_case && !p.inside_if && !p.inside_for {
|
||||
p.tok.lit in table.builtin_type_names)) && !p.inside_match && !p.inside_match_case && !p.inside_if && !p.inside_for {
|
||||
// (p.tok.lit.len in [1, 2] || !p.tok.lit[p.tok.lit.len - 1].is_capital()) &&
|
||||
// || p.table.known_type(p.tok.lit)) {
|
||||
return p.struct_init(false) // short_syntax: false
|
||||
@ -1864,6 +1865,7 @@ fn (p mut Parser) global_decl() ast.GlobalDecl {
|
||||
|
||||
fn (p mut Parser) match_expr() ast.MatchExpr {
|
||||
match_first_pos := p.tok.position()
|
||||
p.inside_match = true
|
||||
p.check(.key_match)
|
||||
is_mut := p.tok.kind in [.key_mut, .key_var]
|
||||
var is_sum_type := false
|
||||
@ -1871,6 +1873,7 @@ fn (p mut Parser) match_expr() ast.MatchExpr {
|
||||
p.next()
|
||||
}
|
||||
cond := p.expr(0)
|
||||
p.inside_match = false
|
||||
p.check(.lcbr)
|
||||
var branches := []ast.MatchBranch
|
||||
for {
|
||||
|
Loading…
Reference in New Issue
Block a user