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

parser: check generic struct init using multi return type (#15472)

This commit is contained in:
yuyi 2022-08-20 16:56:44 +08:00 committed by GitHub
parent 5cba5920d5
commit 0645fe3322
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View File

@ -675,6 +675,9 @@ pub fn (mut p Parser) parse_generic_inst_type(name string) ast.Type {
is_instance = true
}
gts := p.table.sym(gt)
if gts.kind == .multi_return {
p.error_with_pos('cannot use multi return as generic concrete type', type_pos)
}
if !is_instance && gts.name.len > 1 {
p.error_with_pos('generic struct parameter name needs to be exactly one char',
type_pos)

View File

@ -0,0 +1,7 @@
vlib/v/parser/tests/generic_struct_type_using_multi_return_err.vv:6:18: error: cannot use multi return as generic concrete type
4 |
5 | fn main() {
6 | sample := Tuple<(int, int)>{}
| ~~~~~~~~~~
7 | println(sample)
8 | }

View File

@ -0,0 +1,8 @@
struct Tuple<T> {
data T
}
fn main() {
sample := Tuple<(int, int)>{}
println(sample)
}