diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index fc75a1846c..dac72172a1 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1332,6 +1332,12 @@ fn (mut g Gen) stmt(node ast.Stmt) { ast.Import {} ast.InterfaceDecl { // definitions are sorted and added in write_types + for method in node.methods { + if method.return_type.has_flag(.optional) { + // Register an optional if it's not registered yet + g.register_optional(method.return_type) + } + } } ast.Module { // g.is_builtin_mod = node.name == 'builtin' diff --git a/vlib/v/tests/interface_only_decl_with_optional_test.v b/vlib/v/tests/interface_only_decl_with_optional_test.v new file mode 100644 index 0000000000..48dce1a521 --- /dev/null +++ b/vlib/v/tests/interface_only_decl_with_optional_test.v @@ -0,0 +1,8 @@ +interface Message { + serialize() ?[]byte +} + +fn test_interface_only_decl_with_optional() { + println('test interface') + assert true +}