checker: check struct field name duplicate
parent
0dc7a57e1f
commit
a9e33e712a
|
@ -203,7 +203,12 @@ pub fn (mut c Checker) struct_decl(decl ast.StructDecl) {
|
|||
}
|
||||
c.error('struct name must begin with capital letter', pos)
|
||||
}
|
||||
for field in decl.fields {
|
||||
for i, field in decl.fields {
|
||||
for j in 0..i {
|
||||
if field.name == decl.fields[j].name {
|
||||
c.error('field name `$field.name` duplicate', field.pos)
|
||||
}
|
||||
}
|
||||
sym := c.table.get_type_symbol(field.typ)
|
||||
if sym.kind == .placeholder && !decl.is_c && !sym.name.starts_with('C.') {
|
||||
c.error('unknown type `$sym.name`', field.pos)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/struct_field_name_duplicate_err.v:3:4: error: field name `a` duplicate
|
||||
1| struct A {
|
||||
2| a int
|
||||
3| a string
|
||||
~~~~~~
|
||||
4| }
|
||||
5| fn main(){}
|
|
@ -0,0 +1,5 @@
|
|||
struct A {
|
||||
a int
|
||||
a string
|
||||
}
|
||||
fn main(){}
|
|
@ -0,0 +1,5 @@
|
|||
struct A {
|
||||
a int
|
||||
a string
|
||||
}
|
||||
fn main(){}
|
Loading…
Reference in New Issue