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:
parent
bbfa25a17b
commit
ee9cfb6df4
@ -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
|
||||
|
6
vlib/v/checker/tests/multireturn_mix_err.out
Normal file
6
vlib/v/checker/tests/multireturn_mix_err.out
Normal 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 | }
|
7
vlib/v/checker/tests/multireturn_mix_err.vv
Normal file
7
vlib/v/checker/tests/multireturn_mix_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn goo() (string, int) {
|
||||
return '', 100
|
||||
}
|
||||
|
||||
fn foo() (string, int, bool) {
|
||||
return goo(), true
|
||||
}
|
Loading…
Reference in New Issue
Block a user