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

parser: fix error for match sumtype with fntype (#15620)

This commit is contained in:
yuyi 2022-08-31 23:44:12 +08:00 committed by GitHub
parent 6110373519
commit 806c39d46e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -237,7 +237,8 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
} else if (p.tok.kind == .name && !(p.tok.lit == 'C' && p.peek_tok.kind == .dot)
&& (((ast.builtin_type_names_matcher.matches(p.tok.lit) || p.tok.lit[0].is_capital())
&& p.peek_tok.kind != .lpar) || (p.peek_tok.kind == .dot && p.peek_token(2).lit.len > 0
&& p.peek_token(2).lit[0].is_capital()))) || p.is_only_array_type() {
&& p.peek_token(2).lit[0].is_capital()))) || p.is_only_array_type()
|| p.tok.lit == 'fn' {
mut types := []ast.Type{}
for {
// Sum type match

View File

@ -2,5 +2,7 @@ Fn(fn () int)
Fn(fn (int) int)
123
123
123
321
321
321

View File

@ -23,10 +23,24 @@ fn main() {
println(x1())
}
match x1 {
fn () int {
println(x1())
}
else {}
}
x2 := abc(2)
y2 := x2 as fn (int) int
println(y2(321))
if x2 is fn (int) int {
println(x2(321))
}
match x2 {
fn (int) int {
println(x2(321))
}
else {}
}
}