parser: check fn decl multi return types without parentheses (#14508)

yuyi 2022-05-24 10:15:31 +08:00 committed by Jef Roosens
parent b717ef74f8
commit 96b80bcf9f
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 18 additions and 0 deletions

View File

@ -400,6 +400,11 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
p.inside_fn_return = false p.inside_fn_return = false
return_type_pos = return_type_pos.extend(p.prev_tok.pos()) return_type_pos = return_type_pos.extend(p.prev_tok.pos())
} }
if p.tok.kind == .comma {
mr_pos := return_type_pos.extend(p.peek_tok.pos())
p.error_with_pos('multiple return types in function declaration must use parentheses, .e.g (int, string)',
mr_pos)
}
mut type_sym_method_idx := 0 mut type_sym_method_idx := 0
no_body := p.tok.kind != .lcbr no_body := p.tok.kind != .lcbr
end_pos := p.prev_tok.pos() end_pos := p.prev_tok.pos()

View File

@ -0,0 +1,7 @@
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 | }
3 |
4 | fn foo() int, int {
| ~~~~~~~~
5 | return 0, 0
6 | }

View File

@ -0,0 +1,6 @@
fn main() {
}
fn foo() int, int {
return 0, 0
}