mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix generics struct_init (#9661)
This commit is contained in:
parent
cf64001474
commit
9f093203a4
@ -5002,7 +5002,7 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
|
|||||||
g.go_back_out(3)
|
g.go_back_out(3)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sym := g.table.get_final_type_symbol(struct_init.typ)
|
sym := g.table.get_final_type_symbol(g.unwrap_generic(struct_init.typ))
|
||||||
is_amp := g.is_amp
|
is_amp := g.is_amp
|
||||||
is_multiline := struct_init.fields.len > 5
|
is_multiline := struct_init.fields.len > 5
|
||||||
g.is_amp = false // reset the flag immediately so that other struct inits in this expr are handled correctly
|
g.is_amp = false // reset the flag immediately so that other struct inits in this expr are handled correctly
|
||||||
|
15
vlib/v/tests/generics_struct_init_test.v
Normal file
15
vlib/v/tests/generics_struct_init_test.v
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
struct Blah {
|
||||||
|
mut:
|
||||||
|
arr []string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test<T>() T {
|
||||||
|
return T{}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_generics_struct_init() {
|
||||||
|
mut b := test<Blah>()
|
||||||
|
b.arr << 'item'
|
||||||
|
println(b.arr)
|
||||||
|
assert b.arr == ['item']
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user