cgen: fix sumtype with none type (fix #12101) (#12102)

pull/12120/head
yuyi 2021-10-09 08:32:37 +08:00 committed by GitHub
parent 43931be451
commit 3c7c11e55b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -6038,6 +6038,12 @@ fn (mut g Gen) write_types(types []ast.TypeSymbol) {
if typ.name.starts_with('C.') { if typ.name.starts_with('C.') {
continue continue
} }
if typ.kind == .none_ {
g.type_definitions.writeln('struct none {')
g.type_definitions.writeln('\tEMPTY_STRUCT_DECLARATION;')
g.type_definitions.writeln('};')
g.typedefs2.writeln('typedef struct none none;')
}
// sym := g.table.get_type_symbol(typ) // sym := g.table.get_type_symbol(typ)
mut name := typ.cname mut name := typ.cname
match mut typ.info { match mut typ.info {

View File

@ -0,0 +1,5 @@
type MapValue = int | none
fn test_sum_type_with_none_type() {
assert true
}