diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index e23aedfb11..61da187473 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -7043,7 +7043,7 @@ fn (mut g Gen) type_default_impl(typ_ ast.Type, decode_sumtype bool) string { } } else { default_str := g.expr_string_opt(field.typ, field.default_expr) - if default_str.count('\n') > 1 { + if default_str.count(';\n') > 1 { g.type_default_vars.writeln(default_str.all_before_last('\n')) expr_str = default_str.all_after_last('\n') } else { diff --git a/vlib/v/tests/structs/default_expr_array_init_test.v b/vlib/v/tests/structs/default_expr_array_init_test.v new file mode 100644 index 0000000000..8b9a738c7d --- /dev/null +++ b/vlib/v/tests/structs/default_expr_array_init_test.v @@ -0,0 +1,15 @@ +struct Foo { +pub mut: + integer_range_for_discrete []int = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +} + +fn foo(a string) Foo { + return match a { + 'a' { Foo{} } + else { panic('foo') } + } +} + +fn test_main() { + assert foo('a') == Foo{} +}