mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix parsing embedded generic interface using '[]' (#16603)
This commit is contained in:
parent
46bb62955b
commit
a96e2e7093
@ -1,19 +1,19 @@
|
|||||||
vlib/v/checker/tests/generics_interface_decl_no_mention_err.vv:4:2: error: generic type name `T` is not mentioned in interface `Foo<U>`
|
vlib/v/checker/tests/generics_interface_decl_no_mention_err.vv:4:2: error: generic type name `T` is not mentioned in interface `Foo<U>`
|
||||||
2 |
|
2 |
|
||||||
3 | interface Foo[U] {
|
3 | interface Foo[U] {
|
||||||
4 | Bar<T>
|
4 | Bar[T]
|
||||||
| ~~~
|
| ~~~
|
||||||
5 | foo(u U, p P)
|
5 | foo(u U, p P)
|
||||||
6 | bar(u U) []P
|
6 | bar(u U) []P
|
||||||
vlib/v/checker/tests/generics_interface_decl_no_mention_err.vv:5:13: error: generic type name `P` is not mentioned in interface `Foo<U>`
|
vlib/v/checker/tests/generics_interface_decl_no_mention_err.vv:5:13: error: generic type name `P` is not mentioned in interface `Foo<U>`
|
||||||
3 | interface Foo[U] {
|
3 | interface Foo[U] {
|
||||||
4 | Bar<T>
|
4 | Bar[T]
|
||||||
5 | foo(u U, p P)
|
5 | foo(u U, p P)
|
||||||
| ^
|
| ^
|
||||||
6 | bar(u U) []P
|
6 | bar(u U) []P
|
||||||
7 | }
|
7 | }
|
||||||
vlib/v/checker/tests/generics_interface_decl_no_mention_err.vv:6:11: error: generic type name `P` is not mentioned in interface `Foo<U>`
|
vlib/v/checker/tests/generics_interface_decl_no_mention_err.vv:6:11: error: generic type name `P` is not mentioned in interface `Foo<U>`
|
||||||
4 | Bar<T>
|
4 | Bar[T]
|
||||||
5 | foo(u U, p P)
|
5 | foo(u U, p P)
|
||||||
6 | bar(u U) []P
|
6 | bar(u U) []P
|
||||||
| ~~~
|
| ~~~
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
||||||
interface Foo[U] {
|
interface Foo[U] {
|
||||||
Bar<T>
|
Bar[T]
|
||||||
foo(u U, p P)
|
foo(u U, p P)
|
||||||
bar(u U) []P
|
bar(u U) []P
|
||||||
}
|
}
|
||||||
|
@ -569,7 +569,8 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
|
|||||||
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
||||||
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital()
|
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital()
|
||||||
&& (p.peek_tok.line_nr != p.tok.line_nr
|
&& (p.peek_tok.line_nr != p.tok.line_nr
|
||||||
|| p.peek_tok.kind !in [.name, .amp, .lsbr, .lpar]) {
|
|| p.peek_tok.kind !in [.name, .amp, .lsbr, .lpar]
|
||||||
|
|| (p.peek_tok.kind == .lsbr && p.peek_tok.pos - p.tok.pos == p.tok.len)) {
|
||||||
iface_pos := p.tok.pos()
|
iface_pos := p.tok.pos()
|
||||||
mut iface_name := p.tok.lit
|
mut iface_name := p.tok.lit
|
||||||
iface_type := p.parse_type()
|
iface_type := p.parse_type()
|
||||||
@ -624,7 +625,7 @@ 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 {
|
if p.peek_tok.kind in [.lt, .lsbr] && p.peek_tok.pos - p.tok.pos == p.tok.len {
|
||||||
p.error_with_pos("no need to add generic type names in generic interface's method",
|
p.error_with_pos("no need to add generic type names in generic interface's method",
|
||||||
p.peek_tok.pos())
|
p.peek_tok.pos())
|
||||||
return ast.InterfaceDecl{}
|
return ast.InterfaceDecl{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user