diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index 6eb43438a5f203..d6caef9a0d2fb7 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -259,7 +259,8 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string if str_method_expects_ptr { g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(&it);') } else { - g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(it);') + deref, _ := deref_kind(str_method_expects_ptr, info.parent_type.is_ptr(), info.parent_type) + g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(${deref}it);') } g.auto_str_funcs.writeln('\tstring res = str_intp(3, _MOV((StrIntpData[]){ {_SLIT0, ${c.si_s_code}, {.d_s = indents }}, diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index f037958ba1cbea..3d4025fdde75e3 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -22,7 +22,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) { g.empty_line = false g.write(s) } - styp := g.typ(node.typ) + styp := g.typ(g.table.unaliased_type(node.typ)).replace('*', '') mut shared_styp := '' // only needed for shared x := St{... if styp in c.skip_struct_init { // needed for c++ compilers @@ -71,6 +71,10 @@ fn (mut g Gen) struct_init(node ast.StructInit) { g.write('{') } } else { + // alias to pointer type + if g.table.sym(node.typ).kind == .alias && g.table.unaliased_type(node.typ).is_ptr() { + g.write('&') + } if is_multiline { g.writeln('(${styp}){') } else { diff --git a/vlib/v/tests/alias_to_ptr_arg_test.v b/vlib/v/tests/alias_to_ptr_arg_test.v new file mode 100644 index 00000000000000..71571b2a23235f --- /dev/null +++ b/vlib/v/tests/alias_to_ptr_arg_test.v @@ -0,0 +1,16 @@ +struct Foo { + name string + age int +} + +type Boo = &Foo + +fn foo(f Boo) { + println(f) + dump(f) +} + +fn test_main() { + foo(name: '') + assert true +}