From 0645fe3322b007d7569aa284a424ea792d810a74 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 20 Aug 2022 16:56:44 +0800 Subject: [PATCH] parser: check generic struct init using multi return type (#15472) --- vlib/v/parser/parse_type.v | 3 +++ .../tests/generic_struct_type_using_multi_return_err.out | 7 +++++++ .../tests/generic_struct_type_using_multi_return_err.vv | 8 ++++++++ 3 files changed, 18 insertions(+) create mode 100644 vlib/v/parser/tests/generic_struct_type_using_multi_return_err.out create mode 100644 vlib/v/parser/tests/generic_struct_type_using_multi_return_err.vv diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 8cabef9025..5967014305 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -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) diff --git a/vlib/v/parser/tests/generic_struct_type_using_multi_return_err.out b/vlib/v/parser/tests/generic_struct_type_using_multi_return_err.out new file mode 100644 index 0000000000..d04a63bae2 --- /dev/null +++ b/vlib/v/parser/tests/generic_struct_type_using_multi_return_err.out @@ -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 | } diff --git a/vlib/v/parser/tests/generic_struct_type_using_multi_return_err.vv b/vlib/v/parser/tests/generic_struct_type_using_multi_return_err.vv new file mode 100644 index 0000000000..a04cc7d7d3 --- /dev/null +++ b/vlib/v/parser/tests/generic_struct_type_using_multi_return_err.vv @@ -0,0 +1,8 @@ +struct Tuple { + data T +} + +fn main() { + sample := Tuple<(int, int)>{} + println(sample) +}