From c30cda3dafb6dbeb754a9b86fce59896c9db6da7 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 6 Aug 2021 01:20:10 +0800 Subject: [PATCH] v.gen.c: fix error of `println(alias of struct)` (#11062) --- vlib/v/gen/c/fn.v | 6 ----- vlib/v/tests/string_alias_of_struct_test.v | 27 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 vlib/v/tests/string_alias_of_struct_test.v diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index b87d8ea89a..15649442e0 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -962,12 +962,6 @@ fn (mut g Gen) fn_call(node ast.CallExpr) { if typ == 0 { g.checker_bug('print arg.typ is 0', node.pos) } - mut sym := g.table.get_type_symbol(typ) - if mut sym.info is ast.Alias { - typ = sym.info.parent_type - sym = g.table.get_type_symbol(typ) - } - // check if alias parent also not a string if typ != ast.string_type { expr := node.args[0].expr if g.is_autofree && !typ.has_flag(.optional) { diff --git a/vlib/v/tests/string_alias_of_struct_test.v b/vlib/v/tests/string_alias_of_struct_test.v new file mode 100644 index 0000000000..1dcea152d9 --- /dev/null +++ b/vlib/v/tests/string_alias_of_struct_test.v @@ -0,0 +1,27 @@ +interface Foo { + add(x int) +} + +struct Base { +mut: + i int +} + +fn (mut b Base) add(x int) { + b.i += x +} + +type Alias = Base + +fn (mut a Alias) add(x int) { + a.i += x * x +} + +fn test_string_alias_of_struct() { + mut a := Alias{ + i: 2 + } + a.add(3) + println(a) + assert '$a'.contains('Alias') +}