From fe5e3c452faf08df60d0e213a1ebcec1052c1599 Mon Sep 17 00:00:00 2001 From: shadow <49539636+shadowninja55@users.noreply.github.com> Date: Thu, 22 Jul 2021 18:17:16 -0400 Subject: [PATCH] parser: disable generic type aliases (#10917) --- vlib/v/parser/parser.v | 5 +++++ vlib/v/parser/tests/generic_type_alias_decl.out | 3 +++ vlib/v/parser/tests/generic_type_alias_decl.vv | 1 + 3 files changed, 9 insertions(+) create mode 100644 vlib/v/parser/tests/generic_type_alias_decl.out create mode 100644 vlib/v/parser/tests/generic_type_alias_decl.vv diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 2e6cc7d894..72038a22f3 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -3107,6 +3107,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl { } mut sum_variants := []ast.TypeNode{} generic_types := p.parse_generic_type_list() + decl_pos_with_generics := decl_pos.extend(p.prev_tok.position()) p.check(.assign) mut type_pos := p.tok.position() mut comments := []ast.Comment{} @@ -3179,6 +3180,10 @@ fn (mut p Parser) type_decl() ast.TypeDecl { } } // type MyType = int + if generic_types.len > 0 { + p.error_with_pos('generic type aliases are not yet implemented', decl_pos_with_generics) + return ast.AliasTypeDecl{} + } parent_type := first_type parent_sym := p.table.get_type_symbol(parent_type) pidx := parent_type.idx() diff --git a/vlib/v/parser/tests/generic_type_alias_decl.out b/vlib/v/parser/tests/generic_type_alias_decl.out new file mode 100644 index 0000000000..95c9e023f7 --- /dev/null +++ b/vlib/v/parser/tests/generic_type_alias_decl.out @@ -0,0 +1,3 @@ +vlib/v/parser/tests/generic_type_alias_decl.vv:1:1: error: generic type aliases are not yet implemented + 1 | type Pointer = &T + | ~~~~~~~~~~~~~~~ diff --git a/vlib/v/parser/tests/generic_type_alias_decl.vv b/vlib/v/parser/tests/generic_type_alias_decl.vv new file mode 100644 index 0000000000..b2a177a12c --- /dev/null +++ b/vlib/v/parser/tests/generic_type_alias_decl.vv @@ -0,0 +1 @@ +type Pointer = &T