From 3158617ce2e122e96e61f1a54669c8b1516c3ee3 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 19 Apr 2021 19:47:39 +0800 Subject: [PATCH] parser: simplify parse_generic_struct_inst_type() (#9801) --- .../tests/generic_recursive_structs_keep.vv | 28 +++++++++++++++++++ vlib/v/parser/parse_type.v | 7 +---- 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 vlib/v/fmt/tests/generic_recursive_structs_keep.vv diff --git a/vlib/v/fmt/tests/generic_recursive_structs_keep.vv b/vlib/v/fmt/tests/generic_recursive_structs_keep.vv new file mode 100644 index 0000000000..a8704c5749 --- /dev/null +++ b/vlib/v/fmt/tests/generic_recursive_structs_keep.vv @@ -0,0 +1,28 @@ +pub struct Node { + value T + points_to []&Node +} + +fn main() { + mid := &Node{ + value: 'Middle' + } + finish := &Node{ + value: 'Finish' + } + + graph := &Node{ + value: 'Start' + points_to: [ + &Node{ + value: 'TopLeft' + points_to: [ + finish, + mid, + ] + }, + ] + } + + println(graph.points_to[0].value) // 'TopLeft' +} diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index e2619f7dcb..1366c9be37 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -523,11 +523,6 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) ast.Type { } }) return ast.new_type(idx) - } else { - idx := p.table.find_type_idx(name) - if idx != 0 { - return ast.new_type(idx).set_flag(.generic) - } } - return p.parse_enum_or_struct_type(name, .v) + return p.parse_enum_or_struct_type(name, .v).set_flag(.generic) }