Skip to content

Commit 1be5956

Browse files
authored
parser: fix optional fn argument (#15271)
1 parent 0bf2348 commit 1be5956

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

vlib/v/parser/parse_type.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub fn (mut p Parser) parse_type() ast.Type {
379379
p.next()
380380
is_result = true
381381
}
382-
if (is_optional || is_result) && p.tok.line_nr > line_nr {
382+
if (is_optional || is_result) && (p.tok.line_nr > line_nr || p.tok.kind in [.comma, .rpar]) {
383383
mut typ := ast.void_type
384384
if is_optional {
385385
typ = typ.set_flag(.optional)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

vlib/v/tests/inout/optional_fn_arg.vv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module main
2+
3+
fn test(f fn () ?) ? {
4+
return error('test')
5+
}
6+
7+
fn test1() ? {
8+
return error('test1')
9+
}
10+
11+
fn main() {
12+
test(test1) or {
13+
println(err)
14+
return
15+
}
16+
}

0 commit comments

Comments
 (0)