From 8d24522d024cfc72d19672b10012bbff5bf00808 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 16 Jul 2022 21:58:39 +0800 Subject: [PATCH] parser: check generic interface method declaration (#15095) --- .../checker/tests/generic_interface_method_decl_err.out | 6 ++++++ .../v/checker/tests/generic_interface_method_decl_err.vv | 9 +++++++++ vlib/v/parser/struct.v | 5 +++++ 3 files changed, 20 insertions(+) create mode 100644 vlib/v/checker/tests/generic_interface_method_decl_err.out create mode 100644 vlib/v/checker/tests/generic_interface_method_decl_err.vv diff --git a/vlib/v/checker/tests/generic_interface_method_decl_err.out b/vlib/v/checker/tests/generic_interface_method_decl_err.out new file mode 100644 index 0000000000..2a0b194312 --- /dev/null +++ b/vlib/v/checker/tests/generic_interface_method_decl_err.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/generic_interface_method_decl_err.vv:2:8: error: no need to add generic type names in generic interface's method + 1 | interface Expr { + 2 | accept(v Visitor) R + | ^ + 3 | } + 4 | diff --git a/vlib/v/checker/tests/generic_interface_method_decl_err.vv b/vlib/v/checker/tests/generic_interface_method_decl_err.vv new file mode 100644 index 0000000000..59e30df07f --- /dev/null +++ b/vlib/v/checker/tests/generic_interface_method_decl_err.vv @@ -0,0 +1,9 @@ +interface Expr { + accept(v Visitor) R +} + +interface Visitor { +} + +fn main() { +} diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 5c38906d28..45b468b426 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -622,6 +622,11 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { is_mut = true mut_pos = fields.len } + if p.peek_tok.kind == .lt { + p.error_with_pos("no need to add generic type names in generic interface's method", + p.peek_tok.pos()) + return ast.InterfaceDecl{} + } if p.peek_tok.kind == .lpar { method_start_pos := p.tok.pos() line_nr := p.tok.line_nr