From 22fda7c3dddb64c504c6018590b82b41a78b9d3b Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 5 Mar 2022 19:28:48 +0800 Subject: [PATCH] cgen: fix error for time struct init with update (#13660) --- vlib/v/gen/c/struct.v | 2 +- vlib/v/tests/struct_of_time_init_with_update_test.v | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/struct_of_time_init_with_update_test.v diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index 6bcaec0b28..e1e5844646 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -245,7 +245,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) { } } } - g.write(field.name) + g.write(c_name(field.name)) } else { if !g.zero_struct_field(field) { nr_fields-- diff --git a/vlib/v/tests/struct_of_time_init_with_update_test.v b/vlib/v/tests/struct_of_time_init_with_update_test.v new file mode 100644 index 0000000000..5814d8909b --- /dev/null +++ b/vlib/v/tests/struct_of_time_init_with_update_test.v @@ -0,0 +1,12 @@ +import time + +fn test_struct_of_time_init_with_update() { + utc := time.utc() + + t := time.Time{ + ...utc + } + println(utc) + println(t) + assert t == utc +}