From d7c63922d51355ea6caf13ae0b5efd9cf9dbb986 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Sun, 7 Jun 2020 22:15:27 +0530 Subject: [PATCH] parser: allow void return type for C functions --- vlib/v/parser/parse_type.v | 2 +- vlib/v/tests/inout/c_fn_can_return_void_type.out | 1 + vlib/v/tests/inout/c_fn_can_return_void_type.vv | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/inout/c_fn_can_return_void_type.out create mode 100644 vlib/v/tests/inout/c_fn_can_return_void_type.vv diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 6ad3c961cc..44e968e130 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -136,7 +136,7 @@ pub fn (mut p Parser) parse_type() table.Type { if p.tok.kind != .lcbr { pos := p.tok.position() typ = p.parse_any_type(language, nr_muls > 0) - if typ == table.void_type { + if typ == table.void_type && is_optional { p.error_with_pos('use `?` instead of `?void`', pos) } } diff --git a/vlib/v/tests/inout/c_fn_can_return_void_type.out b/vlib/v/tests/inout/c_fn_can_return_void_type.out new file mode 100644 index 0000000000..9766475a41 --- /dev/null +++ b/vlib/v/tests/inout/c_fn_can_return_void_type.out @@ -0,0 +1 @@ +ok diff --git a/vlib/v/tests/inout/c_fn_can_return_void_type.vv b/vlib/v/tests/inout/c_fn_can_return_void_type.vv new file mode 100644 index 0000000000..f10bea8f42 --- /dev/null +++ b/vlib/v/tests/inout/c_fn_can_return_void_type.vv @@ -0,0 +1,4 @@ +fn C.some_c_function(int) void +fn main() { + println('ok') +}