cgen: fix codegen for a const assigned a fixed array, initialized with unsafe exprs (fix #23674) (#23676)

This commit is contained in:
Felipe Pena 2025-02-09 04:30:44 -03:00 committed by GitHub
parent 0632822fd4
commit 4c14e8e8de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 0 deletions

View File

@ -6102,6 +6102,9 @@ fn (mut g Gen) check_expr_is_const(expr ast.Expr) bool {
ast.PrefixExpr {
return expr.right is ast.Ident || g.check_expr_is_const(expr.right)
}
ast.UnsafeExpr {
return g.check_expr_is_const(expr.expr)
}
else {
return false
}

View File

@ -0,0 +1 @@
Array_fixed_int_literal_ptr1_8 weapon_keys = {&_const_main__key_weapon1, &_const_main__key_weapon2, &_const_main__key_weapon3, &_const_main__key_weapon4, &_const_main__key_weapon5, &_const_main__key_weapon6, &_const_main__key_weapon7, &_const_main__key_weapon8}; // fixed array const

View File

@ -0,0 +1,15 @@
// vtest vflags: -no-skip-unused
const key_weapon1 = 1
const key_weapon2 = 1
const key_weapon3 = 1
const key_weapon4 = 1
const key_weapon5 = 1
const key_weapon6 = 1
const key_weapon7 = 1
const key_weapon8 = 1
@[export: 'weapon_keys']
const weapon_keys = [unsafe { &key_weapon1 }, unsafe { &key_weapon2 }, unsafe { &key_weapon3 },
unsafe { &key_weapon4 }, unsafe { &key_weapon5 }, unsafe { &key_weapon6 }, unsafe { &key_weapon7 },
unsafe { &key_weapon8 }]!