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

parser: check generic interface method declaration (#15095)

This commit is contained in:
yuyi 2022-07-16 21:58:39 +08:00 committed by GitHub
parent 5e0899853b
commit 8d24522d02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -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<R>(v Visitor<R>) R
| ^
3 | }
4 |

View File

@ -0,0 +1,9 @@
interface Expr {
accept<R>(v Visitor<R>) R
}
interface Visitor<R> {
}
fn main() {
}

View File

@ -622,6 +622,11 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
is_mut = true is_mut = true
mut_pos = fields.len 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 { if p.peek_tok.kind == .lpar {
method_start_pos := p.tok.pos() method_start_pos := p.tok.pos()
line_nr := p.tok.line_nr line_nr := p.tok.line_nr