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:
parent
6b2d3a826b
commit
09630dd0bc
@ -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)
|
||||
|
5
vlib/v/parser/tests/interface_name_err.out
Normal file
5
vlib/v/parser/tests/interface_name_err.out
Normal 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
|
19
vlib/v/parser/tests/interface_name_err.vv
Normal file
19
vlib/v/parser/tests/interface_name_err.vv
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user