From 64eb4c491358149b501353bfda0dd8b154c7531a Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 28 Sep 2024 11:40:16 -0300 Subject: [PATCH] cgen: fix struct init field with alias to array fixed (fix #22339) (#22341) --- vlib/v/gen/c/struct.v | 2 +- .../struct_init_alias_array_fixed_test.v | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/structs/struct_init_alias_array_fixed_test.v diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index 9af7d8ec0..5cc175b91 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -649,7 +649,7 @@ fn (mut g Gen) struct_init_field(sfield ast.StructInitField, language ast.Langua g.inside_cast_in_heap = 0 // prevent use of pointers in child structs field_unwrap_typ := g.unwrap_generic(sfield.typ) - field_unwrap_sym := g.table.sym(field_unwrap_typ) + field_unwrap_sym := g.table.final_sym(field_unwrap_typ) if field_unwrap_sym.kind == .array_fixed && sfield.expr in [ast.Ident, ast.SelectorExpr] { info := field_unwrap_sym.info as ast.ArrayFixed g.fixed_array_var_init(g.expr_string(sfield.expr), sfield.expr.is_auto_deref_var(), diff --git a/vlib/v/tests/structs/struct_init_alias_array_fixed_test.v b/vlib/v/tests/structs/struct_init_alias_array_fixed_test.v new file mode 100644 index 000000000..e76a1d393 --- /dev/null +++ b/vlib/v/tests/structs/struct_init_alias_array_fixed_test.v @@ -0,0 +1,23 @@ +module main + +type Mat4 = [16]f32 + +struct VsParams { + mv Mat4 + mvp Mat4 +} + +struct Camera { + mv Mat4 + mvp Mat4 +} + +fn test_main() { + camera := Camera{} + vs_uniforms := VsParams{ + mv: camera.mv + mvp: camera.mvp + } + assert vs_uniforms.mv.len == 16 + assert vs_uniforms.mvp.len == 16 +} -- 2.39.5