ast, cgen: fix const fixed array of reference value (#13022)

pull/13023/head
yuyi 2022-01-04 16:36:29 +08:00 committed by GitHub
parent 4b55800ffd
commit 00a0c1886e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -835,7 +835,7 @@ pub fn (t &Table) array_fixed_cname(elem_type Type, size int) string {
if elem_type.is_ptr() {
res = '_ptr$elem_type.nr_muls()'
}
return 'Array_fixed_${elem_type_sym.cname}_$size' + res
return 'Array_fixed_$elem_type_sym.cname${res}_$size'
}
[inline]

View File

@ -1138,6 +1138,9 @@ pub fn (mut g Gen) write_typedef_types() {
if fixed.starts_with('C__') {
fixed = fixed[3..]
}
if fixed.contains('ptr') {
fixed = 'void*'
}
if elem_sym.info is ast.FnType {
pos := g.out.len
g.write_fn_ptr_decl(&elem_sym.info, '')

View File

@ -0,0 +1,10 @@
const (
foo = u32(1)
bar = u32(2)
weapon_keys = [&foo, &bar]!
)
fn test_const_fixed_array_of_ref_value() {
assert weapon_keys[0] == &foo
assert weapon_keys[1] == &bar
}