diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index e59e8d015c..f8fcda3164 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -379,7 +379,7 @@ pub fn (mut p Parser) parse_type() ast.Type { p.next() is_result = true } - if (is_optional || is_result) && p.tok.line_nr > line_nr { + if (is_optional || is_result) && (p.tok.line_nr > line_nr || p.tok.kind in [.comma, .rpar]) { mut typ := ast.void_type if is_optional { typ = typ.set_flag(.optional) diff --git a/vlib/v/tests/inout/optional_fn_arg.out b/vlib/v/tests/inout/optional_fn_arg.out new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/vlib/v/tests/inout/optional_fn_arg.out @@ -0,0 +1 @@ +test diff --git a/vlib/v/tests/inout/optional_fn_arg.vv b/vlib/v/tests/inout/optional_fn_arg.vv new file mode 100644 index 0000000000..1ddd18e82a --- /dev/null +++ b/vlib/v/tests/inout/optional_fn_arg.vv @@ -0,0 +1,16 @@ +module main + +fn test(f fn () ?) ? { + return error('test') +} + +fn test1() ? { + return error('test1') +} + +fn main() { + test(test1) or { + println(err) + return + } +}