Skip to content

Commit 615a9a0

Browse files
authored
cgen: fix generic type init syntax for primitive types (#21872)
1 parent aa34047 commit 615a9a0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

vlib/v/gen/c/struct.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
148148
}
149149
}
150150
inited_fields[field_name] = i
151-
if sym.kind != .struct_ {
151+
if sym.kind != .struct_ && (sym.kind == .string || !sym.is_primitive()) {
152152
if init_field.typ == 0 {
153153
g.checker_bug('struct init, field.typ is 0', init_field.pos)
154154
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn func[I]() I {
2+
return I{0}
3+
}
4+
5+
fn test_main() {
6+
assert func[f64]() == 0.0
7+
assert func[int]() == 0
8+
assert func[bool]() == false
9+
}

0 commit comments

Comments
 (0)