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

parser: fix parse error when using f<Foo<int> > (#9401)

This commit is contained in:
zakuro 2021-03-21 20:09:43 +09:00 committed by GitHub
parent 0e80e57aa5
commit dfd58293ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -1694,7 +1694,7 @@ fn (p &Parser) is_typename(t token.Token) bool {
// heuristics to detect `func<T>()` from `var < expr`
// 1. `f<[]` is generic(e.g. `f<[]int>`) because `var < []` is invalid
// 2. `f<map[` is generic(e.g. `f<map[string]string>)
// 3. `f<foo>` is generic because `v1 < foo > v2` is invalid syntax
// 3. `f<foo>` and `f<foo<` are generic because `v1 < foo > v2` and `v1 < foo < v2` are invalid syntax
// 4. `f<Foo,` is generic when Foo is typename.
// otherwise it is not generic because it may be multi-value (e.g. `return f < foo, 0`).
// 5. `f<mod.Foo>` is same as case 3
@ -1727,7 +1727,7 @@ fn (p &Parser) is_generic_call() bool {
return true
}
return match kind3 {
.gt { true } // case 3
.gt, .lt { true } // case 3
.comma { p.is_typename(tok2) } // case 4
// case 5 and 6
.dot { kind4 == .name && (kind5 == .gt || (kind5 == .comma && p.is_typename(tok4))) }

View File

@ -437,6 +437,8 @@ fn test_generic_detection() {
// generic
assert multi_generic_args<int, string>(0, 's')
assert multi_generic_args<Foo1, Foo2>(Foo1{}, Foo2{})
assert multi_generic_args<Foo<int>, Foo<int> >(Foo<int>{}, Foo<int>{})
// TODO: assert multi_generic_args<Foo<int>, Foo<int>>(Foo1{}, Foo2{})
assert multi_generic_args<simplemodule.Data, int>(simplemodule.Data{}, 0)
assert multi_generic_args<int, simplemodule.Data>(0, simplemodule.Data{})
assert multi_generic_args<[]int, int>([]int{}, 0)