From 731015cd9b3599363a3e82921afe83f922d4e83e Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 14 Dec 2021 14:11:11 +0800 Subject: [PATCH] ci: revert "cgen: fix embedded struct init with complex fields (fix #12823) (#12825)" (#12830) This reverts commit b4b2a21453e6b2b65e7390eb99fb12485a512380. --- vlib/v/gen/c/cgen.v | 15 +++---------- .../struct_init_with_complex_fields_test.v | 21 ------------------- 2 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 vlib/v/tests/struct_init_with_complex_fields_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index dbdbcca1fd..af4bc7aea3 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6807,20 +6807,11 @@ fn (mut g Gen) type_default(typ_ ast.Type) string { || field_sym.kind in [.array, .map, .string, .bool, .alias, .i8, .i16, .int, .i64, .byte, .u16, .u32, .u64, .char, .voidptr, .byteptr, .charptr, .struct_] { field_name := c_name(field.name) if field.has_default_expr { - mut expr_str := '' - if g.table.get_type_symbol(field.typ).kind in [.sum_type, .interface_] { - expr_str = g.expr_string_with_cast(field.default_expr, - field.default_expr_typ, field.typ) - } else { - expr_str = g.expr_string(field.default_expr) - } + expr_str := g.expr_string_with_cast(field.default_expr, field.default_expr_typ, + field.typ) init_str += '.$field_name = $expr_str,' } else { - mut zero_str := g.type_default(field.typ) - if zero_str == '{0}' { - zero_str = '{EMPTY_STRUCT_INITIALIZATION}' - } - init_str += '.$field_name = $zero_str,' + init_str += '.$field_name = ${g.type_default(field.typ)},' } has_none_zero = true } diff --git a/vlib/v/tests/struct_init_with_complex_fields_test.v b/vlib/v/tests/struct_init_with_complex_fields_test.v deleted file mode 100644 index f119e98b34..0000000000 --- a/vlib/v/tests/struct_init_with_complex_fields_test.v +++ /dev/null @@ -1,21 +0,0 @@ -struct Bar {} - -type Fnc = fn () - -struct Foo { - Bar - fnc_fn Fnc = voidptr(0) -} - -struct App { -mut: - foo Foo -} - -fn test_struct_init_with_complex_fields() { - mut app := App{} - println(app) - ret := '$app' - assert ret.contains('Bar: Bar{}') - assert ret.contains('fnc_fn: fn ()') -}