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:
parent
99eb9fdaab
commit
448938be0d
@ -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
|
||||
|
13
vlib/v/tests/generics_anon_fn_decl_with_type_only_arg_test.v
Normal file
13
vlib/v/tests/generics_anon_fn_decl_with_type_only_arg_test.v
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user