mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
Merge 5581b8c8b8
into a8d200ac0e
This commit is contained in:
commit
78dea06e1d
2 changed files with 14 additions and 2 deletions
|
@ -7591,7 +7591,7 @@ fn (mut g Gen) type_default_impl(typ_ ast.Type, decode_sumtype bool) string {
|
||||||
field_sym := g.table.sym(field.typ)
|
field_sym := g.table.sym(field.typ)
|
||||||
is_option := field.typ.has_flag(.option)
|
is_option := field.typ.has_flag(.option)
|
||||||
if is_option || field.has_default_expr
|
if is_option || field.has_default_expr
|
||||||
|| field_sym.kind in [.enum, .array_fixed, .array, .map, .string, .bool, .alias, .i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .voidptr, .byteptr, .charptr, .struct, .chan, .sum_type] {
|
|| field_sym.kind in [.enum, .array_fixed, .array, .map, .string, .bool, .alias, .i8, .i16, .i32, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .voidptr, .byteptr, .charptr, .struct, .chan, .sum_type] {
|
||||||
if sym.language == .c && !field.has_default_expr && !is_option {
|
if sym.language == .c && !field.has_default_expr && !is_option {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -7668,7 +7668,7 @@ fn (mut g Gen) type_default_impl(typ_ ast.Type, decode_sumtype bool) string {
|
||||||
if has_none_zero {
|
if has_none_zero {
|
||||||
init_str += '}'
|
init_str += '}'
|
||||||
if !typ_is_shared_f {
|
if !typ_is_shared_f {
|
||||||
type_name := if info.is_anon || g.inside_global_decl {
|
type_name := if info.is_anon || g.inside_global_decl || g.inside_const {
|
||||||
// No name needed for anon structs, C figures it out on its own.
|
// No name needed for anon structs, C figures it out on its own.
|
||||||
''
|
''
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -20,3 +20,15 @@ fn test_main() {
|
||||||
assert dump(f) == [foo.num_elements]DummyStruct{}
|
assert dump(f) == [foo.num_elements]DummyStruct{}
|
||||||
assert dump(d) == [foo.num_elements]DummyStruct{}
|
assert dump(d) == [foo.num_elements]DummyStruct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DummyStruct2 {
|
||||||
|
dummy_item1 int
|
||||||
|
dummy_item2 i32
|
||||||
|
dummy_item3 u8
|
||||||
|
}
|
||||||
|
|
||||||
|
const m = [foo.num_elements]DummyStruct2{}
|
||||||
|
|
||||||
|
fn test_many_dummy_fields_with_diff_types() {
|
||||||
|
assert dump(m) == [foo.num_elements]DummyStruct2{}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue