From 5faabe7464d8d7cd089523117992c5c731b7abba Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 5 Feb 2022 18:52:37 +0200 Subject: [PATCH] Revert "cgen: fix error for struct with reference alias fields (#13374)" This reverts commit 4d485ae687f87f5651c351fef261a784f80af32f. --- vlib/v/gen/c/auto_str_methods.v | 3 +-- vlib/v/gen/c/cgen.v | 3 --- vlib/v/gen/c/str.v | 3 --- vlib/v/tests/struct_with_reference_alias_fields.v | 13 ------------- 4 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 vlib/v/tests/struct_with_reference_alias_fields.v diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index b13af61b35..84fb9db0f5 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -916,8 +916,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri funcprefix += 'isnil(it.${c_name(field.name)})' funcprefix += ' ? _SLIT("nil") : ' // struct, floats and ints have a special case through the _str function - if sym.kind !in [.struct_, .alias] && !field.typ.is_int_valptr() - && !field.typ.is_float_valptr() { + if sym.kind != .struct_ && !field.typ.is_int_valptr() && !field.typ.is_float_valptr() { funcprefix += '*' } } diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index ed08d1804c..42fde59c49 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5519,9 +5519,6 @@ fn (mut g Gen) struct_init(node ast.StructInit) { || sfield.typ.is_pointer()) && !sfield.typ.is_number() { g.write('/* autoref */&') } - if sfield.typ.is_ptr() && field_type_sym.kind == .alias { - g.write('&') - } g.expr_with_cast(sfield.expr, sfield.typ, sfield.expected_type) } } diff --git a/vlib/v/gen/c/str.v b/vlib/v/gen/c/str.v index fc9f1090e5..604e14d1d4 100644 --- a/vlib/v/gen/c/str.v +++ b/vlib/v/gen/c/str.v @@ -85,9 +85,6 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { g.expr(expr) g.write(')') } else if typ == ast.string_type { - if etype.is_ptr() { - g.write('*') - } g.expr(expr) } else if typ == ast.bool_type { g.expr(expr) diff --git a/vlib/v/tests/struct_with_reference_alias_fields.v b/vlib/v/tests/struct_with_reference_alias_fields.v deleted file mode 100644 index 564e388750..0000000000 --- a/vlib/v/tests/struct_with_reference_alias_fields.v +++ /dev/null @@ -1,13 +0,0 @@ -type SS = string - -struct ST { - data &SS -} - -fn test_struct_with_reference_alias_fields() { - mut val := ST{ - data: &SS('hi') - } - println(val.data) - assert '$val.data' == 'hi' -}