parser: fix a match error
parent
caed4aad58
commit
93b942de46
|
@ -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' }
|
|
@ -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
|
ast_imports []ast.Import
|
||||||
is_amp bool
|
is_amp bool
|
||||||
returns bool
|
returns bool
|
||||||
|
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{}`
|
||||||
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
|
||||||
}
|
}
|
||||||
|
@ -691,7 +692,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
||||||
node = x
|
node = x
|
||||||
}
|
}
|
||||||
} else if p.peek_tok.kind == .lcbr && (p.tok.lit[0].is_capital() || is_c || (p.builtin_mod &&
|
} 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.tok.lit.len in [1, 2] || !p.tok.lit[p.tok.lit.len - 1].is_capital()) &&
|
||||||
// || p.table.known_type(p.tok.lit)) {
|
// || p.table.known_type(p.tok.lit)) {
|
||||||
return p.struct_init(false) // short_syntax: false
|
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 {
|
fn (p mut Parser) match_expr() ast.MatchExpr {
|
||||||
match_first_pos := p.tok.position()
|
match_first_pos := p.tok.position()
|
||||||
|
p.inside_match = true
|
||||||
p.check(.key_match)
|
p.check(.key_match)
|
||||||
is_mut := p.tok.kind in [.key_mut, .key_var]
|
is_mut := p.tok.kind in [.key_mut, .key_var]
|
||||||
var is_sum_type := false
|
var is_sum_type := false
|
||||||
|
@ -1871,6 +1873,7 @@ fn (p mut Parser) match_expr() ast.MatchExpr {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
cond := p.expr(0)
|
cond := p.expr(0)
|
||||||
|
p.inside_match = false
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
var branches := []ast.MatchBranch
|
var branches := []ast.MatchBranch
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Reference in New Issue