From ccd2252cf345bc7421cedcdbd9937d4b2db327d9 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Thu, 29 May 2025 04:28:03 -0300 Subject: [PATCH] checker: fix struct update expr checking, when an alias is used (fix #24581) (#24582) --- vlib/v/checker/struct.v | 4 ++-- .../v/tests/aliases/alias_updated_expr_test.v | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 vlib/v/tests/aliases/alias_updated_expr_test.v diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 88e5b3f15..ee7197ecd 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -916,8 +916,8 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', s := c.table.type_to_str(update_type) c.error('expected struct, found `${s}`', node.update_expr.pos()) } else if update_type != node.typ { - from_sym := c.table.sym(update_type) - to_sym := c.table.sym(node.typ) + from_sym := c.table.final_sym(update_type) + to_sym := c.table.final_sym(node.typ) from_info := from_sym.info as ast.Struct to_info := to_sym.info as ast.Struct // TODO: this check is too strict diff --git a/vlib/v/tests/aliases/alias_updated_expr_test.v b/vlib/v/tests/aliases/alias_updated_expr_test.v new file mode 100644 index 000000000..cf6aaacce --- /dev/null +++ b/vlib/v/tests/aliases/alias_updated_expr_test.v @@ -0,0 +1,21 @@ +module main + +struct Cfg { + item string +} + +type AliasCfg = Cfg + +fn foo(cfg &AliasCfg) { + var := &AliasCfg{ + ...cfg + item: 'foo' + } + assert var.item == 'foo' +} + +fn test_main() { + foo(AliasCfg{ + item: 'bar' + }) +} -- 2.39.5