Skip to content

Commit ccd2252

Browse files
authored
checker: fix struct update expr checking, when an alias is used (fix #24581) (#24582)
1 parent 464e297 commit ccd2252

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

vlib/v/checker/struct.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,8 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
916916
s := c.table.type_to_str(update_type)
917917
c.error('expected struct, found `${s}`', node.update_expr.pos())
918918
} else if update_type != node.typ {
919-
from_sym := c.table.sym(update_type)
920-
to_sym := c.table.sym(node.typ)
919+
from_sym := c.table.final_sym(update_type)
920+
to_sym := c.table.final_sym(node.typ)
921921
from_info := from_sym.info as ast.Struct
922922
to_info := to_sym.info as ast.Struct
923923
// TODO: this check is too strict
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module main
2+
3+
struct Cfg {
4+
item string
5+
}
6+
7+
type AliasCfg = Cfg
8+
9+
fn foo(cfg &AliasCfg) {
10+
var := &AliasCfg{
11+
...cfg
12+
item: 'foo'
13+
}
14+
assert var.item == 'foo'
15+
}
16+
17+
fn test_main() {
18+
foo(AliasCfg{
19+
item: 'bar'
20+
})
21+
}

0 commit comments

Comments
 (0)