1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix fixed array global variable (fix #14712) (#14730)

This commit is contained in:
yuyi 2022-06-09 21:53:19 +08:00 committed by GitHub
parent be23ddc253
commit 922f003729
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -0,0 +1 @@
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

View File

@ -0,0 +1,9 @@
module main
__global (
heap = [10]u8{}
)
fn main() {
println(heap)
}

View File

@ -4667,7 +4667,8 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
if field.has_expr || cinit {
if g.pref.translated {
g.definitions.write_string(' = ${g.expr_string(field.expr)}')
} else if (field.expr.is_literal() && should_init) || cinit {
} else if (field.expr.is_literal() && should_init) || cinit
|| (field.expr is ast.ArrayInit && (field.expr as ast.ArrayInit).is_fixed) {
// Simple literals can be initialized right away in global scope in C.
// e.g. `int myglobal = 10;`
g.definitions.write_string(' = ${g.expr_string(field.expr)}')