fixes #2346
This commit is contained in:
parent
bc264618f5
commit
bf90b9c833
9 changed files with 107 additions and 97 deletions
|
|
@ -1,43 +0,0 @@
|
|||
discard """
|
||||
output: '''1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
a
|
||||
b
|
||||
t
|
||||
e
|
||||
s
|
||||
t
|
||||
'''
|
||||
"""
|
||||
|
||||
template accept(e: expr) =
|
||||
static: assert compiles(e)
|
||||
|
||||
template reject(e: expr) =
|
||||
static: assert(not compiles(e))
|
||||
|
||||
type
|
||||
Container[T] = generic C
|
||||
C.len is Ordinal
|
||||
items(c) is iterator
|
||||
for value in C:
|
||||
type(value) is T
|
||||
|
||||
proc takesIntContainer(c: Container[int]) =
|
||||
for e in c: echo e
|
||||
|
||||
takesIntContainer(@[1, 2, 3])
|
||||
reject takesIntContainer(@["x", "y"])
|
||||
|
||||
proc takesContainer(c: Container) =
|
||||
for e in c: echo e
|
||||
|
||||
takesContainer(@[4, 5, 6])
|
||||
takesContainer(@["a", "b"])
|
||||
takesContainer "test"
|
||||
reject takesContainer(10)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue