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

parser: fix generic anon fn decl with type only argument (#14124)

This commit is contained in:
yuyi 2022-04-21 17:53:13 +08:00 committed by GitHub
parent 99eb9fdaab
commit 448938be0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -783,9 +783,10 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
} else {
p.tok.lit
}
is_generic_type := p.tok.kind == .name && p.tok.lit.len == 1 && p.tok.lit[0].is_capital()
types_only := p.tok.kind in [.amp, .ellipsis, .key_fn, .lsbr]
|| (p.peek_tok.kind == .comma && p.table.known_type(argname))
|| (p.peek_tok.kind == .comma && (p.table.known_type(argname) || is_generic_type))
|| p.peek_tok.kind == .dot || p.peek_tok.kind == .rpar
|| (p.tok.kind == .key_mut && (p.peek_token(2).kind == .comma
|| p.peek_token(2).kind == .rpar || (p.peek_tok.kind == .name

View File

@ -0,0 +1,13 @@
fn test_generics_anon_fn_decl_with_type_only_arg() {
ret := func_b<int>(11, 22, add)
println(ret)
assert ret == 33
}
fn add(a int, b int) int {
return a + b
}
fn func_b<T>(x T, y T, f fn (T, T) T) T {
return f(x, y)
}