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

checker: disallow multiple return values in const declarations (#18273)

This commit is contained in:
Turiiya 2023-05-27 00:55:14 +02:00 committed by GitHub
parent 6db62e43d3
commit 3e08487198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View File

@ -1531,6 +1531,13 @@ fn (mut c Checker) const_decl(mut node ast.ConstDecl) {
} }
c.error('duplicate const `${field.name}`', name_pos) c.error('duplicate const `${field.name}`', name_pos)
} }
if field.expr is ast.CallExpr {
sym := c.table.sym(c.check_expr_opt_call(field.expr, c.expr(field.expr)))
if sym.kind == .multi_return {
c.error('const declarations do not support multiple return values yet',
field.expr.pos)
}
}
c.const_names << field.name c.const_names << field.name
} }
for i, mut field in node.fields { for i, mut field in node.fields {

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/const_decl_multi_return_err.vv:6:6: error: const declarations do not support multiple return values yet
4 |
5 | const (
6 | a = foo()
| ~~~~~
7 | )
8 |

View File

@ -0,0 +1,12 @@
fn foo() (int, int, int) {
return 1, 2, 3
}
const (
a = foo()
)
fn main() {
println("$a")
}