mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check struct field name duplicate
This commit is contained in:
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)
|
||||
|
7
vlib/v/checker/tests/struct_field_name_duplicate_err.out
Normal file
7
vlib/v/checker/tests/struct_field_name_duplicate_err.out
Normal file
@ -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(){}
|
5
vlib/v/checker/tests/struct_field_name_duplicate_err.v
Normal file
5
vlib/v/checker/tests/struct_field_name_duplicate_err.v
Normal file
@ -0,0 +1,5 @@
|
||||
struct A {
|
||||
a int
|
||||
a string
|
||||
}
|
||||
fn main(){}
|
5
vlib/v/checker/tests/struct_field_name_duplicate_err.vv
Normal file
5
vlib/v/checker/tests/struct_field_name_duplicate_err.vv
Normal file
@ -0,0 +1,5 @@
|
||||
struct A {
|
||||
a int
|
||||
a string
|
||||
}
|
||||
fn main(){}
|
Loading…
Reference in New Issue
Block a user