Skip to content

Commit

Permalink
Fix ..< iterator (#11103)
Browse files Browse the repository at this point in the history
* add iterator overloads

* add test
  • Loading branch information
krux02 authored May 3, 2019
1 parent 515ab81 commit 9c3e23e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,20 @@ when defined(nimNewRoof):
yield i
inc i

template dotdotLessImpl(t) {.dirty.} =
iterator `..<`*(a, b: t): t {.inline.} =
## A type specialized version of ``..<`` for convenience so that
## mixing integer types works better.
var res = a
while res < b:
yield res
inc(res)

dotdotLessImpl(int64)
dotdotLessImpl(int32)
dotdotLessImpl(uint64)
dotdotLessImpl(uint32)

else:
iterator countup*[S, T](a: S, b: T, step = 1): T {.inline.} =
## Counts from ordinal value `a` up to `b` (inclusive) with the given
Expand Down
20 changes: 18 additions & 2 deletions tests/iter/tcountup.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
discard """
output: "0123456789"
output: '''
0123456789
0.0
'''
"""

# Test new countup

for i in 0 ..< 10'i64:
stdout.write(i)
echo "\n"

echo()

# 11099

var
x: uint32
y: float

for i in 0 ..< x:
if i == 1: echo i
y += 1

echo y

0 comments on commit 9c3e23e

Please sign in to comment.