mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix const aliases of bytes fixed array (#15701)
This commit is contained in:
parent
fc8e3d0971
commit
5c900e23de
@ -1296,7 +1296,7 @@ static inline void __${sym.cname}_pushval($sym.cname ch, $el_stype val) {
|
||||
}
|
||||
}
|
||||
for sym in g.table.type_symbols {
|
||||
if sym.kind == .alias && sym.name !in c.builtins {
|
||||
if sym.kind == .alias && sym.name !in c.builtins && sym.name !in ['byte', 'i32'] {
|
||||
g.write_alias_typesymbol_declaration(sym)
|
||||
}
|
||||
}
|
||||
@ -4561,6 +4561,20 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) {
|
||||
// "Simple" expressions are not going to need multiple statements,
|
||||
// only the ones which are inited later, so it's safe to use expr_string
|
||||
g.const_decl_simple_define(field.mod, field.name, g.expr_string(field_expr))
|
||||
} else if field.expr is ast.CastExpr {
|
||||
if field.expr.expr is ast.ArrayInit {
|
||||
if field.expr.expr.is_fixed {
|
||||
styp := g.typ(field.expr.typ)
|
||||
val := g.expr_string(field.expr.expr)
|
||||
g.global_const_defs[util.no_dots(field.name)] = GlobalConstDef{
|
||||
mod: field.mod
|
||||
def: '$styp $const_name = $val; // fixed array const'
|
||||
dep_names: g.table.dependent_names_in_expr(field_expr)
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
g.const_decl_init_later(field.mod, name, field.expr, field.typ, false)
|
||||
} else {
|
||||
g.const_decl_init_later(field.mod, name, field.expr, field.typ, false)
|
||||
}
|
||||
|
@ -616,7 +616,8 @@ typedef uint64_t u64;
|
||||
typedef uint32_t u32;
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
//typedef uint8_t byte;
|
||||
typedef u8 byte;
|
||||
typedef int i32;
|
||||
typedef uint32_t rune;
|
||||
typedef size_t usize;
|
||||
typedef ptrdiff_t isize;
|
||||
|
9
vlib/v/tests/const_from_bytes_test.v
Normal file
9
vlib/v/tests/const_from_bytes_test.v
Normal file
@ -0,0 +1,9 @@
|
||||
type UUID = [16]byte
|
||||
|
||||
const codec_test_uuid = UUID([byte(0x6b), 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4,
|
||||
0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8]!)
|
||||
|
||||
fn test_const_from_bytes() {
|
||||
println(codec_test_uuid)
|
||||
assert true
|
||||
}
|
Loading…
Reference in New Issue
Block a user