mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
test cases for the new handling of iterators by the is operator
This commit is contained in:
@@ -323,11 +323,6 @@ proc isOpImpl(c: PContext, n: PNode): PNode =
|
||||
result = newIntNode(nkIntLit, ord(t.kind == tyProc and
|
||||
t.callConv == ccClosure and
|
||||
tfIterator notin t.flags))
|
||||
of "iterator":
|
||||
let t = skipTypes(t1, abstractRange)
|
||||
result = newIntNode(nkIntLit, ord(t.kind == tyProc and
|
||||
t.callConv == ccClosure and
|
||||
tfIterator in t.flags))
|
||||
else:
|
||||
var t2 = n[2].typ.skipTypes({tyTypeDesc})
|
||||
let lifted = liftParamType(c, skType, newNodeI(nkArgList, n.info),
|
||||
|
||||
@@ -410,7 +410,10 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||
return isNone
|
||||
when useEffectSystem:
|
||||
if not compatibleEffects(f, a): return isNone
|
||||
of tyNil: result = f.allowsNil
|
||||
of tyNil:
|
||||
result = f.allowsNil
|
||||
of tyIter:
|
||||
if tfIterator in f.flags: result = typeRel(c, f.base, a.base)
|
||||
else: discard
|
||||
|
||||
proc typeRangeRel(f, a: PType): TTypeRelation {.noinline.} =
|
||||
@@ -923,8 +926,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
||||
result = isNone
|
||||
|
||||
of tyIter:
|
||||
if a.kind == f.kind: result = typeRel(c, f.base, a.base)
|
||||
else: result = isNone
|
||||
if a.kind == tyIter or
|
||||
(a.kind == tyProc and tfIterator in a.flags):
|
||||
result = typeRel(c, f.base, a.base)
|
||||
else:
|
||||
result = isNone
|
||||
|
||||
of tyStmt:
|
||||
result = isGeneric
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
discard """
|
||||
output: "true true false yes"
|
||||
output: '''true
|
||||
true
|
||||
false
|
||||
yes'''
|
||||
"""
|
||||
|
||||
proc IsVoid[T](): string =
|
||||
@@ -11,3 +14,26 @@ proc IsVoid[T](): string =
|
||||
const x = int is int
|
||||
echo x, " ", float is float, " ", float is string, " ", IsVoid[void]()
|
||||
|
||||
template yes(e: expr): stmt =
|
||||
static: assert e
|
||||
|
||||
template no(e: expr): stmt =
|
||||
static: assert(not e)
|
||||
|
||||
var s = @[1, 2, 3]
|
||||
|
||||
yes s.items is iterator
|
||||
no s.items is proc
|
||||
|
||||
yes s.items is iterator: int
|
||||
no s.items is iterator: float
|
||||
|
||||
yes s.items is iterator: TNumber
|
||||
no s.items is iterator: object
|
||||
|
||||
type
|
||||
Iter[T] = iterator: T
|
||||
|
||||
yes s.items is Iter[TNumber]
|
||||
no s.items is Iter[float]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user