cgen: fix default value init for union sum types (#6795)

pull/6794/head^2
Daniel Däschle 2020-11-11 18:56:13 +01:00 committed by GitHub
parent a4acb70c64
commit 43ce098043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -5295,7 +5295,7 @@ fn (mut g Gen) type_default(typ_ table.Type) string {
else {} else {}
} }
return match sym.kind { return match sym.kind {
.interface_, .sum_type, .array_fixed, .multi_return { '{0}' } .interface_, .union_sum_type, .sum_type, .array_fixed, .multi_return { '{0}' }
.alias { g.type_default((sym.info as table.Alias).parent_type) } .alias { g.type_default((sym.info as table.Alias).parent_type) }
else { '0' } else { '0' }
} }

View File

@ -432,6 +432,15 @@ fn test_match_multi_branch() {
} }
} }
struct Outer2 {
e Expr4
}
fn test_zero_value_init() {
// no c compiler error then it's successful
o := Outer2{}
}
fn test_sum_type_match() { fn test_sum_type_match() {
// TODO: Remove these casts // TODO: Remove these casts
assert is_gt_simple('3', int(2)) assert is_gt_simple('3', int(2))