test for ``map`` defined as inline iterator
This commit is contained in:
Zahary Karadjov
2014-03-09 14:02:01 +02:00
parent 518b794491
commit 4b09a89758
3 changed files with 47 additions and 3 deletions

View File

@@ -82,7 +82,7 @@ proc notFoundError*(c: PContext, n: PNode, errors: seq[string]) =
# fail fast:
globalError(n.info, errTypeMismatch, "")
var result = msgKindToString(errTypeMismatch)
add(result, describeArgs(c, n, 1 + ord(nfDotField in n.flags)))
add(result, describeArgs(c, n, 1))
add(result, ')')
var candidates = ""
@@ -114,7 +114,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
var errors: seq[string]
var usedSyms: seq[PNode]
template pickBest(headSymbol: expr) =
pickBestCandidate(c, headSymbol, n, orig, initialBinding,
filter, result, alt, errors)
@@ -166,7 +166,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
n.sons[0..1] = [callOp, n[1], calleeName]
orig.sons[0..1] = [callOp, orig[1], calleeName]
pickBest(callOp)
if overloadsState == csEmpty and result.state == csEmpty:
localError(n.info, errUndeclaredIdentifier, considerAcc(f).s)
return
@@ -175,9 +175,15 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
localError(n.info, errExprXCannotBeCalled,
renderTree(n, {renderNoComments}))
else:
if {nfDotField, nfDotSetter} * n.flags != {}:
# clean up the inserted ops
n.sons.delete(2)
n.sons[0] = f
errors = @[]
pickBest(f)
notFoundError(c, n, errors)
return
if alt.state == csMatch and cmpCandidates(result, alt) == 0 and

26
tests/iter/titerable.nim Normal file
View File

@@ -0,0 +1,26 @@
discard """
output: '''2
4
6
4
8
12
'''
"""
iterator map[T, U](s: iterator:T{.inline.}, f: proc(x: T): U): U =
for e in s: yield f(e)
template toSeq(s: expr): expr =
var res = newSeq[type(s)](0)
for e in s: res.add(e)
res
var s1 = @[1, 2, 3]
for x in map(s1.items, proc (a:int): int = a*2):
echo x
var s2 = toSeq(map(s1.items, proc (a:int): int = a*4))
for x in s2:
echo x

View File

@@ -0,0 +1,12 @@
discard """
msg: 'type mismatch: got (PTest)'
"""
type
PTest = ref object
proc test(x: PTest, y: int) = nil
var buf: PTest
buf.test()