diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index ee2a9d0cb23206..d007f88191e6cc 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -148,7 +148,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) { } } inited_fields[field_name] = i - if sym.kind != .struct_ { + if sym.kind != .struct_ && (sym.kind == .string || !sym.is_primitive()) { if init_field.typ == 0 { g.checker_bug('struct init, field.typ is 0', init_field.pos) } diff --git a/vlib/v/tests/generic_init_syntax_test.v b/vlib/v/tests/generic_init_syntax_test.v new file mode 100644 index 00000000000000..793528546295c2 --- /dev/null +++ b/vlib/v/tests/generic_init_syntax_test.v @@ -0,0 +1,9 @@ +fn func[I]() I { + return I{0} +} + +fn test_main() { + assert func[f64]() == 0.0 + assert func[int]() == 0 + assert func[bool]() == false +}