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

ci: fix failing ./v vlib/builtin/builtin_test.v (globals initialisation)

This commit is contained in:
Delyan Angelov 2022-07-21 21:49:00 +03:00
parent ed43bfc469
commit dc1b54c669
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 15 additions and 2 deletions

View File

@ -151,7 +151,9 @@ fn (mut g Gen) final_gen_str(typ StrType) {
g.gen_str_for_thread(sym.info, styp, str_fn_name)
}
else {
verror('could not generate string method `$str_fn_name` for type `$styp`')
if sym.name != 'nil' {
verror('could not generate string method `$str_fn_name` for type `$styp`')
}
}
}
}

View File

@ -4709,10 +4709,21 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
continue
}
if field.has_expr || cinit {
// `__global x = unsafe { nil }` should still use the simple direct initialisation, `g_main_argv` needs it.
mut is_simple_unsafe_expr := false
if field.expr is ast.UnsafeExpr {
if field.expr.expr is ast.Nil {
is_simple_unsafe_expr = true
}
if field.expr.expr.is_literal() {
is_simple_unsafe_expr = true
}
}
if g.pref.translated {
def_builder.write_string(' = ${g.expr_string(field.expr)}')
} else if (field.expr.is_literal() && should_init) || cinit
|| (field.expr is ast.ArrayInit && (field.expr as ast.ArrayInit).is_fixed) {
|| (field.expr is ast.ArrayInit && (field.expr as ast.ArrayInit).is_fixed)
|| is_simple_unsafe_expr {
// Simple literals can be initialized right away in global scope in C.
// e.g. `int myglobal = 10;`
def_builder.write_string(' = ${g.expr_string(field.expr)}')