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:
parent
6db62e43d3
commit
3e08487198
@ -1531,6 +1531,13 @@ fn (mut c Checker) const_decl(mut node ast.ConstDecl) {
|
||||
}
|
||||
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
|
||||
}
|
||||
for i, mut field in node.fields {
|
||||
|
7
vlib/v/checker/tests/const_decl_multi_return_err.out
Normal file
7
vlib/v/checker/tests/const_decl_multi_return_err.out
Normal 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 |
|
12
vlib/v/checker/tests/const_decl_multi_return_err.vv
Normal file
12
vlib/v/checker/tests/const_decl_multi_return_err.vv
Normal file
@ -0,0 +1,12 @@
|
||||
fn foo() (int, int, int) {
|
||||
return 1, 2, 3
|
||||
}
|
||||
|
||||
const (
|
||||
a = foo()
|
||||
)
|
||||
|
||||
|
||||
fn main() {
|
||||
println("$a")
|
||||
}
|
Loading…
Reference in New Issue
Block a user