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:
parent
374186f1f7
commit
70f466460f
@ -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) {')
|
||||
for field in info.fields {
|
||||
field_name := c_name(field.name)
|
||||
sym := g.table.sym(g.unwrap_generic(field.typ))
|
||||
|
||||
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)
|
||||
}
|
||||
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 {
|
||||
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('}')
|
||||
|
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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user