Skip to content

Commit

Permalink
cgen: fix type_default for array init >= 8 items (spotted while build…
Browse files Browse the repository at this point in the history
…ing the vhamll project) (#23334)
  • Loading branch information
felipensp authored Jan 1, 2025
1 parent 87c0a9c commit a366582
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions vlib/v/tests/structs/default_expr_array_init_test.v
Original file line number Diff line number Diff line change
@@ -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{}
}

0 comments on commit a366582

Please sign in to comment.