cgen: fix type_default for array init >= 8 items (spotted while building the vhamll project) (#23334)

This commit is contained in:
Felipe Pena 2025-01-01 20:50:38 -03:00 committed by GitHub
parent 87c0a9ce28
commit a366582010
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -7043,7 +7043,7 @@ fn (mut g Gen) type_default_impl(typ_ ast.Type, decode_sumtype bool) string {
} }
} else { } else {
default_str := g.expr_string_opt(field.typ, field.default_expr) 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')) g.type_default_vars.writeln(default_str.all_before_last('\n'))
expr_str = default_str.all_after_last('\n') expr_str = default_str.all_after_last('\n')
} else { } else {

View File

@ -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{}
}