refactor illegal iterator assignment detection (#12212)

* refactor illegal iterator assignment detection

* delete crappy test
This commit is contained in:
Arne Döring 2019-10-11 08:43:58 +02:00 • committed by Andreas Rumpf
commit 7cf3395d85
9 changed files with 54 additions and 54 deletions

View file

@ -1,27 +0,0 @@
discard """
output: '''(1, 1)
(2, 2)
(3, 3)
@[1, 2, 3, 4]
'''
"""
iterator zip[T1, T2](a: openarray[T1], b: openarray[T2]): iterator() {.inline.} =
let len = min(a.len, b.len)
for i in 0..<len:
echo (a[i], b[i])
proc foo(args: varargs[int]) =
for i in zip(args,args):
discard
foo(1,2,3)
# 10999
proc varargsToSeq(vals: varargs[int32]): seq[int32] =
result = newSeqOfCap[int32](vals.len)
for v in vals:
result.add v
echo varargsToSeq(1, 2, 3, 4)

View file

@ -0,0 +1,14 @@
discard """
output: '''
@[1, 2, 3, 4]
'''
"""
# issue #10999
proc varargsToSeq(vals: varargs[int32]): seq[int32] =
result = newSeqOfCap[int32](vals.len)
for v in vals:
result.add v
echo varargsToSeq(1, 2, 3, 4)

View file

@ -0,0 +1,28 @@
discard """
cmd: "nim check $file"
errmsg: ""
nimout: '''
ttypeAllowed.nim(13, 5) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe, locks: 0.}' for let
ttypeAllowed.nim(17, 7) Error: invalid type for const: iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe, locks: 0.}
ttypeAllowed.nim(21, 5) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe, locks: 0.}' for var
ttypeAllowed.nim(26, 10) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe, locks: 0.}' for result
'''
"""
let f1 = case true
of true: countup[int]
of false: countdown[int]
const f2 = case true
of true: countup[int]
of false: countdown[int]
var f3 = case true
of true: countup[int]
of false: countdown[int]
proc foobar(): auto =
result = case true
of true: countup[int]
of false: countdown[int]

View file

@ -1,8 +0,0 @@
discard """
errormsg: "inline iterators are not first-class / cannot be assigned to variables"
line: 8
"""
iterator foo: int =
yield 2
let x = foo