1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: add check for mixing multi-return results with other types in return statements (fix #17501) (#18067)

This commit is contained in:
Felipe Pena 2023-04-27 10:50:09 -03:00 committed by GitHub
parent bbfa25a17b
commit ee9cfb6df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -82,6 +82,9 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
// Unpack multi return types
sym := c.table.sym(typ)
if sym.kind == .multi_return {
if i > 0 || i != node.exprs.len - 1 {
c.error('cannot use multi-return with other return types', expr.pos())
}
for t in sym.mr_info().types {
got_types << t
expr_idxs << i

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/multireturn_mix_err.vv:6:9: error: cannot use multi-return with other return types
4 |
5 | fn foo() (string, int, bool) {
6 | return goo(), true
| ~~~~~
7 | }

View File

@ -0,0 +1,7 @@
fn goo() (string, int) {
return '', 100
}
fn foo() (string, int, bool) {
return goo(), true
}