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

parser: fix parsing generic types using '[]' in anon fn decl (#16605)

This commit is contained in:
yuyi 2022-12-07 00:15:59 +08:00 committed by GitHub
parent cf015e5073
commit 921416d821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,6 @@
vlib/v/checker/tests/assign_generic_fn_err.vv:2:9: error: cannot assign generic function to a variable
1 | fn main() {
2 | fun := fn <T> (value T) T {
2 | fun := fn [T] (value T) T {
| ~~~~~~~~~~~~~~~~~~~~
3 | return value
4 | }

View File

@ -1,5 +1,5 @@
fn main() {
fun := fn <T> (value T) T {
fun := fn [T] (value T) T {
return value
}

View File

@ -687,7 +687,12 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
p.close_scope()
}
p.scope.detached_from_parent = true
inherited_vars := if p.tok.kind == .lsbr { p.closure_vars() } else { []ast.Param{} }
inherited_vars := if p.tok.kind == .lsbr && !(p.peek_tok.kind == .name
&& p.peek_tok.lit.len == 1 && p.peek_tok.lit[0].is_capital()) {
p.closure_vars()
} else {
[]ast.Param{}
}
_, generic_names := p.parse_generic_types()
args, _, is_variadic := p.fn_args()
for arg in args {