mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add error for for x in t {, where t.next() returns multiple values
(Fix #9459).
This commit is contained in:
@@ -61,6 +61,10 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
|
|||||||
if !next_fn.return_type.has_flag(.optional) {
|
if !next_fn.return_type.has_flag(.optional) {
|
||||||
c.error('iterator method `next()` must return an optional', node.cond.position())
|
c.error('iterator method `next()` must return an optional', node.cond.position())
|
||||||
}
|
}
|
||||||
|
return_sym := c.table.sym(next_fn.return_type)
|
||||||
|
if return_sym.kind == .multi_return {
|
||||||
|
c.error('iterator method `next()` must not return multiple values', node.cond.position())
|
||||||
|
}
|
||||||
// the receiver
|
// the receiver
|
||||||
if next_fn.params.len != 1 {
|
if next_fn.params.len != 1 {
|
||||||
c.error('iterator method `next()` must have 0 parameters', node.cond.position())
|
c.error('iterator method `next()` must have 0 parameters', node.cond.position())
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/for_in_iterator_returning_multiple_values_err.vv:8:10: error: iterator method `next()` must not return multiple values
|
||||||
|
6 |
|
||||||
|
7 | t := TestStruct{}
|
||||||
|
8 | for x in t {
|
||||||
|
| ^
|
||||||
|
9 | println(x) // ('foo', 'bar')
|
||||||
|
10 | break
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
struct TestStruct {}
|
||||||
|
|
||||||
|
fn (t TestStruct) next() ?(string, string) {
|
||||||
|
return 'foo', 'bar'
|
||||||
|
}
|
||||||
|
|
||||||
|
t := TestStruct{}
|
||||||
|
for x in t {
|
||||||
|
println(x) // ('foo', 'bar')
|
||||||
|
break
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user