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

parser: check interface name using single letter capital (#14878)

This commit is contained in:
yuyi 2022-06-28 13:29:23 +08:00 committed by GitHub
parent 6b2d3a826b
commit 09630dd0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -493,6 +493,11 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
return ast.InterfaceDecl{}
}
modless_name := p.check_name()
if modless_name.len == 1 && modless_name[0].is_capital() {
p.error_with_pos('single letter capital names are reserved for generic template types.',
name_pos)
return ast.InterfaceDecl{}
}
if modless_name == 'IError' && p.mod != 'builtin' {
p.error_with_pos('cannot register interface `IError`, it is builtin interface type',
name_pos)

View File

@ -0,0 +1,5 @@
vlib/v/parser/tests/interface_name_err.vv:1:11: error: single letter capital names are reserved for generic template types.
1 | interface A {
| ^
2 | a int
3 | b() int

View File

@ -0,0 +1,19 @@
interface A {
a int
b() int
}
struct Ba {
a int
}
fn (b &Ba) b() int {
return b.a
}
fn main() {
a := &Ba{
a: 1
}
b := A(a)
}