From 3849cdcecc1ce465963ad05d7b2c4977fdd3de8a Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 26 May 2022 09:20:22 +0800 Subject: [PATCH] fmt: fix fn return types list ending with comma (#14529) --- vlib/v/fmt/tests/fn_types_list_ending_with_comma_expected.vv | 5 +++++ vlib/v/fmt/tests/fn_types_list_ending_with_comma_input.vv | 5 +++++ vlib/v/parser/parse_type.v | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/fn_types_list_ending_with_comma_expected.vv create mode 100644 vlib/v/fmt/tests/fn_types_list_ending_with_comma_input.vv diff --git a/vlib/v/fmt/tests/fn_types_list_ending_with_comma_expected.vv b/vlib/v/fmt/tests/fn_types_list_ending_with_comma_expected.vv new file mode 100644 index 0000000000..6db65de1b2 --- /dev/null +++ b/vlib/v/fmt/tests/fn_types_list_ending_with_comma_expected.vv @@ -0,0 +1,5 @@ +fn ok(a int) (int, string) { + return 11, 'hello' +} + +fn main() {} diff --git a/vlib/v/fmt/tests/fn_types_list_ending_with_comma_input.vv b/vlib/v/fmt/tests/fn_types_list_ending_with_comma_input.vv new file mode 100644 index 0000000000..41e4be6980 --- /dev/null +++ b/vlib/v/fmt/tests/fn_types_list_ending_with_comma_input.vv @@ -0,0 +1,5 @@ +fn ok(a int,) (int, string,) { + return 11, 'hello' +} + +fn main() {} diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index cc6fd76f42..5be771f0d2 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -198,7 +198,7 @@ pub fn (mut p Parser) parse_multi_return_type() ast.Type { p.check(.lpar) mut mr_types := []ast.Type{} mut has_generic := false - for p.tok.kind != .eof { + for p.tok.kind !in [.eof, .rpar] { mr_type := p.parse_type() if mr_type.idx() == 0 { break