Skip to content

Commit a5b98cb

Browse files
authored
parser: check fn decl multi return types without parentheses (#14508)
1 parent 5ade39f commit a5b98cb

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

vlib/v/parser/fn.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
400400
p.inside_fn_return = false
401401
return_type_pos = return_type_pos.extend(p.prev_tok.pos())
402402
}
403+
if p.tok.kind == .comma {
404+
mr_pos := return_type_pos.extend(p.peek_tok.pos())
405+
p.error_with_pos('multiple return types in function declaration must use parentheses, .e.g (int, string)',
406+
mr_pos)
407+
}
403408
mut type_sym_method_idx := 0
404409
no_body := p.tok.kind != .lcbr
405410
end_pos := p.prev_tok.pos()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
vlib/v/parser/tests/fn_decl_multi_return_types_err.vv:4:10: error: multiple return types in function declaration must use parentheses, .e.g (int, string)
2+
2 | }
3+
3 |
4+
4 | fn foo() int, int {
5+
| ~~~~~~~~
6+
5 | return 0, 0
7+
6 | }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
}
3+
4+
fn foo() int, int {
5+
return 0, 0
6+
}

0 commit comments

Comments
 (0)