mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix struct field name generation in auto free (#15440)
This commit is contained in:
@ -72,6 +72,7 @@ fn (mut g Gen) gen_free_for_struct(info ast.Struct, styp string, fn_name string)
|
|||||||
}
|
}
|
||||||
fn_builder.writeln('void ${fn_name}($styp* it) {')
|
fn_builder.writeln('void ${fn_name}($styp* it) {')
|
||||||
for field in info.fields {
|
for field in info.fields {
|
||||||
|
field_name := c_name(field.name)
|
||||||
sym := g.table.sym(g.unwrap_generic(field.typ))
|
sym := g.table.sym(g.unwrap_generic(field.typ))
|
||||||
|
|
||||||
if sym.kind !in [.string, .array, .map, .struct_] {
|
if sym.kind !in [.string, .array, .map, .struct_] {
|
||||||
@ -88,9 +89,9 @@ fn (mut g Gen) gen_free_for_struct(info ast.Struct, styp string, fn_name string)
|
|||||||
g.gen_free_method(field.typ)
|
g.gen_free_method(field.typ)
|
||||||
}
|
}
|
||||||
if is_shared {
|
if is_shared {
|
||||||
fn_builder.writeln('\t${field_styp_fn_name}(&(it->$field.name->val));')
|
fn_builder.writeln('\t${field_styp_fn_name}(&(it->$field_name->val));')
|
||||||
} else {
|
} else {
|
||||||
fn_builder.writeln('\t${field_styp_fn_name}(&(it->$field.name));')
|
fn_builder.writeln('\t${field_styp_fn_name}(&(it->$field_name));')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn_builder.writeln('}')
|
fn_builder.writeln('}')
|
||||||
|
6
vlib/v/gen/c/testdata/struct_field_free.out
vendored
Normal file
6
vlib/v/gen/c/testdata/struct_field_free.out
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
&Class{
|
||||||
|
class: 'abc'
|
||||||
|
register: '123'
|
||||||
|
namespace: '456'
|
||||||
|
normal: 'xyz'
|
||||||
|
}
|
15
vlib/v/gen/c/testdata/struct_field_free.vv
vendored
Normal file
15
vlib/v/gen/c/testdata/struct_field_free.vv
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// Test, that the autogenerated `free` method compiles,
|
||||||
|
// on a struct that has field names that are C/C++ keywords.
|
||||||
|
|
||||||
|
struct Class {
|
||||||
|
class string
|
||||||
|
register string
|
||||||
|
namespace string
|
||||||
|
normal string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
class := &Class{'abc', '123', '456', 'xyz'}
|
||||||
|
println(class)
|
||||||
|
class.free()
|
||||||
|
}
|
Reference in New Issue
Block a user