Skip to content

Commit ec865cf

Browse files
authored
parser: check interface methods name (fix #14217) (#14218)
1 parent 317acfd commit ec865cf

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vlib/v/checker/tests/interface_method_name_err.vv:2:2: error: method name `Fizz` cannot contain uppercase letters, use snake_case instead
2+
1 | interface Foo {
3+
2 | Fizz()
4+
| ~~~~~~
5+
3 | }
6+
4 |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface Foo {
2+
Fizz()
3+
}
4+
5+
fn main() {
6+
}

vlib/v/parser/struct.v

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
516516
mut mut_pos := -1
517517
mut ifaces := []ast.InterfaceEmbedding{}
518518
for p.tok.kind != .rcbr && p.tok.kind != .eof {
519-
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital() {
519+
if p.tok.kind == .name && p.tok.lit.len > 0 && p.tok.lit[0].is_capital()
520+
&& p.peek_tok.kind != .lpar {
520521
iface_pos := p.tok.pos()
521522
mut iface_name := p.tok.lit
522523
iface_type := p.parse_type()
@@ -584,10 +585,6 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
584585
p.error_with_pos('duplicate method `$name`', method_start_pos)
585586
return ast.InterfaceDecl{}
586587
}
587-
if language == .v && util.contains_capital(name) {
588-
p.error('interface methods cannot contain uppercase letters, use snake_case instead')
589-
return ast.InterfaceDecl{}
590-
}
591588
// field_names << name
592589
args2, _, is_variadic := p.fn_args() // TODO merge ast.Param and ast.Arg to avoid this
593590
mut args := [

0 commit comments

Comments
 (0)