mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
compiler: enforce reserved keywords replacement
* compiler: Enforce reserved keywords replacement on empty value initialization * compiler: Add test for reserved keywords enforcement A new struct has been introduced in the tests that contains all C reserved keywords that are not reserved in V. Some read and write are tested too.
This commit is contained in:
parent
fd2d9c214c
commit
5c79c0e743
2 changed files with 99 additions and 54 deletions
|
@ -3029,9 +3029,10 @@ fn (p mut Parser) struct_init(typ string) string {
|
|||
}
|
||||
// Zero values: init all fields (ints to 0, strings to '' etc)
|
||||
for i, field in t.fields {
|
||||
sanitized_name := if typ != 'Option' { p.table.var_cgen_name( field.name ) } else { field.name }
|
||||
// println('### field.name')
|
||||
// Skip if this field has already been assigned to
|
||||
if field.name in inited_fields {
|
||||
if sanitized_name in inited_fields {
|
||||
continue
|
||||
}
|
||||
field_typ := field.typ
|
||||
|
@ -3040,9 +3041,9 @@ fn (p mut Parser) struct_init(typ string) string {
|
|||
}
|
||||
// init map fields
|
||||
if field_typ.starts_with('map_') {
|
||||
p.gen_struct_field_init(field.name)
|
||||
p.gen_struct_field_init(sanitized_name)
|
||||
p.gen_empty_map(field_typ.right(4))
|
||||
inited_fields << field.name
|
||||
inited_fields << sanitized_name
|
||||
if i != t.fields.len - 1 {
|
||||
p.gen(',')
|
||||
}
|
||||
|
@ -3051,7 +3052,7 @@ fn (p mut Parser) struct_init(typ string) string {
|
|||
}
|
||||
def_val := type_default(field_typ)
|
||||
if def_val != '' && def_val != '{0}' {
|
||||
p.gen_struct_field_init(field.name)
|
||||
p.gen_struct_field_init(sanitized_name)
|
||||
p.gen(def_val)
|
||||
if i != t.fields.len - 1 {
|
||||
p.gen(',')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue