parser: do not allow 1 char struct names

pull/5075/head
Alexander Medvednikov 2020-05-27 16:00:00 +02:00
parent 5423a15f46
commit 670820cc59
3 changed files with 6 additions and 3 deletions

View File

@ -1,4 +1,4 @@
vlib/v/checker/tests/struct_pub_field.v:9:4: error: field `i` of struct `A` is immutable
vlib/v/checker/tests/struct_pub_field.v:9:4: error: field `i` of struct `Foo` is immutable
7 | i: 1
8 | }
9 | a.i = 2

View File

@ -1,9 +1,9 @@
struct A {
struct Foo {
i int
}
fn main() {
a := A{
a := Foo{
i: 1
}
a.i = 2

View File

@ -41,6 +41,9 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
if language == .v && p.mod != 'builtin' && name.len > 0 && !name[0].is_capital() {
p.error_with_pos('struct name `$name` must begin with capital letter', end_pos)
}
if name.len == 1 {
p.error_with_pos('struct names must have more than one character', end_pos)
}
// println('struct decl $name')
mut ast_fields := []ast.StructField{}
mut fields := []table.Field{}