From b7ca4c1668ac58d1e510b223542285e81f7f386c Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 12 May 2022 11:36:25 +0300 Subject: [PATCH] checker: fix a compiler panic on `fntest()?(&int,&int){return test()?}` --- vlib/v/checker/return.v | 2 +- .../v/checker/tests/return_optional_of_multiple_results.out | 6 ++++++ vlib/v/checker/tests/return_optional_of_multiple_results.vv | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/return_optional_of_multiple_results.out create mode 100644 vlib/v/checker/tests/return_optional_of_multiple_results.vv diff --git a/vlib/v/checker/return.v b/vlib/v/checker/return.v index f739244371..35de9d77ca 100644 --- a/vlib/v/checker/return.v +++ b/vlib/v/checker/return.v @@ -135,7 +135,7 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) { pos) } if exp_type.is_ptr() && got_typ.is_ptr() { - mut r_expr := &node.exprs[i] + mut r_expr := &node.exprs[expr_idxs[i]] if mut r_expr is ast.Ident { if mut r_expr.obj is ast.Var { mut obj := unsafe { &r_expr.obj } diff --git a/vlib/v/checker/tests/return_optional_of_multiple_results.out b/vlib/v/checker/tests/return_optional_of_multiple_results.out new file mode 100644 index 0000000000..8a7d972083 --- /dev/null +++ b/vlib/v/checker/tests/return_optional_of_multiple_results.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/return_optional_of_multiple_results.vv:2:9: error: `?` is not needed, use `return test()` + 1 | fn test() ?(&int, &int) { + 2 | return test() ? + | ~~~~~~ + 3 | } + 4 | diff --git a/vlib/v/checker/tests/return_optional_of_multiple_results.vv b/vlib/v/checker/tests/return_optional_of_multiple_results.vv new file mode 100644 index 0000000000..fc89b13df1 --- /dev/null +++ b/vlib/v/checker/tests/return_optional_of_multiple_results.vv @@ -0,0 +1,6 @@ +fn test() ?(&int, &int) { + return test() ? +} + +fn main() { +}