diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 570e4d8741..85e90aaa3c 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6963,7 +6963,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) { if sym.info.fields.len > 0 { g.writeln('\t// pointers to common sumtype fields') for field in sym.info.fields { - g.type_definitions.writeln('\t${g.styp(field.typ.ref())} ${c_name(field.name)};') + g.type_definitions.writeln('\t${g.styp(field.typ)}* ${c_name(field.name)};') } } g.type_definitions.writeln('};') diff --git a/vlib/v/tests/sumtypes/sumtype_with_embedded_struct_of_option_field_test.v b/vlib/v/tests/sumtypes/sumtype_with_embedded_struct_of_option_field_test.v new file mode 100644 index 0000000000..85ce114b31 --- /dev/null +++ b/vlib/v/tests/sumtypes/sumtype_with_embedded_struct_of_option_field_test.v @@ -0,0 +1,30 @@ +struct Value { + x int +} + +struct BValue { + v ?Value +} + +struct Word { + BValue +} + +struct Long { + BValue +} + +struct Variadic { + BValue +} + +type Param = Word | Long | Variadic + +fn test_sumtype_with_embedded_struct_of_option_field() { + a := [Param(Word{}), Long{}, Variadic{}] + dump(a) + f := a[0] + v := f.v + dump(v) + assert v == none +}