Skip to content

Commit

Permalink
cgen: fix generic type init syntax for primitive types (#21872)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jul 15, 2024
1 parent aa34047 commit 615a9a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
}
}
inited_fields[field_name] = i
if sym.kind != .struct_ {
if sym.kind != .struct_ && (sym.kind == .string || !sym.is_primitive()) {
if init_field.typ == 0 {
g.checker_bug('struct init, field.typ is 0', init_field.pos)
}
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/tests/generic_init_syntax_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn func[I]() I {
return I{0}
}

fn test_main() {
assert func[f64]() == 0.0
assert func[int]() == 0
assert func[bool]() == false
}

0 comments on commit 615a9a0

Please sign in to comment.