Skip to content

Commit 16f5f45

Browse files
authored
cgen: correct T{} init for []Type aliases (fix #25962) (#25963)
1 parent 4d7e357 commit 16f5f45

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

vlib/v/gen/c/struct.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
5252
g.write(g.type_default_sumtype(unwrapped_typ, sym))
5353
}
5454
return
55-
} else if sym.kind == .map {
55+
} else if sym.kind == .map || (sym.kind == .array && node.init_fields.len == 0) {
5656
g.write(g.type_default(unwrapped_typ))
5757
return
5858
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module value
2+
3+
pub interface Value {
4+
str() string
5+
}
6+
7+
pub type List = []Value
8+
9+
pub fn (x List) str() string {
10+
return x.str()
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module value
2+
3+
fn test_list() {
4+
mut list := make_list()!
5+
assert (list as List).len == 0
6+
}
7+
8+
fn make_list() !Value {
9+
mut list := List{}
10+
return list
11+
}

0 commit comments

Comments
 (0)