From 3c7c11e55bdc9f766dff27d77ddad4a440f6b7c0 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 9 Oct 2021 08:32:37 +0800 Subject: [PATCH] cgen: fix sumtype with none type (fix #12101) (#12102) --- vlib/v/gen/c/cgen.v | 6 ++++++ vlib/v/tests/sum_type_with_none_type_test.v | 5 +++++ 2 files changed, 11 insertions(+) create mode 100644 vlib/v/tests/sum_type_with_none_type_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index d06ae08cb0..c7210c74dd 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6038,6 +6038,12 @@ fn (mut g Gen) write_types(types []ast.TypeSymbol) { if typ.name.starts_with('C.') { 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) mut name := typ.cname match mut typ.info { diff --git a/vlib/v/tests/sum_type_with_none_type_test.v b/vlib/v/tests/sum_type_with_none_type_test.v new file mode 100644 index 0000000000..148381fffa --- /dev/null +++ b/vlib/v/tests/sum_type_with_none_type_test.v @@ -0,0 +1,5 @@ +type MapValue = int | none + +fn test_sum_type_with_none_type() { + assert true +}