parent
105a472dc5
commit
bfa3d62cc1
4 changed files with 35 additions and 4 deletions
|
|
@ -271,7 +271,7 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
|
||||||
localError(c.config, n.info, errXExpectsTypeOrValue % opToStr[m])
|
localError(c.config, n.info, errXExpectsTypeOrValue % opToStr[m])
|
||||||
else:
|
else:
|
||||||
n.sons[1] = semExprWithType(c, n.sons[1], {efDetermineType})
|
n.sons[1] = semExprWithType(c, n.sons[1], {efDetermineType})
|
||||||
var typ = skipTypes(n.sons[1].typ, abstractVarRange + {tyTypeDesc})
|
var typ = skipTypes(n.sons[1].typ, abstractVarRange + {tyTypeDesc, tyUserTypeClassInst})
|
||||||
case typ.kind
|
case typ.kind
|
||||||
of tySequence, tyString, tyCString, tyOpenArray, tyVarargs:
|
of tySequence, tyString, tyCString, tyOpenArray, tyVarargs:
|
||||||
n.typ = getSysType(c.graph, n.info, tyInt)
|
n.typ = getSysType(c.graph, n.info, tyInt)
|
||||||
|
|
@ -1261,7 +1261,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# make sure we don't evaluate generic macros/templates
|
# make sure we don't evaluate generic macros/templates
|
||||||
n.sons[0] = semExprWithType(c, n.sons[0],
|
n.sons[0] = semExprWithType(c, n.sons[0],
|
||||||
{efNoEvaluateGeneric})
|
{efNoEvaluateGeneric})
|
||||||
let arr = skipTypes(n.sons[0].typ, {tyGenericInst,
|
let arr = skipTypes(n.sons[0].typ, {tyGenericInst, tyUserTypeClassInst,
|
||||||
tyVar, tyLent, tyPtr, tyRef, tyAlias, tySink})
|
tyVar, tyLent, tyPtr, tyRef, tyAlias, tySink})
|
||||||
case arr.kind
|
case arr.kind
|
||||||
of tyArray, tyOpenArray, tyVarargs, tySequence, tyString,
|
of tyArray, tyOpenArray, tyVarargs, tySequence, tyString,
|
||||||
|
|
|
||||||
|
|
@ -619,7 +619,7 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode =
|
||||||
of mLow:
|
of mLow:
|
||||||
result = newIntNodeT(firstOrd(g.config, n.sons[1].typ), n, g)
|
result = newIntNodeT(firstOrd(g.config, n.sons[1].typ), n, g)
|
||||||
of mHigh:
|
of mHigh:
|
||||||
if skipTypes(n.sons[1].typ, abstractVar).kind notin
|
if skipTypes(n.sons[1].typ, abstractVar+{tyUserTypeClassInst}).kind notin
|
||||||
{tySequence, tyString, tyCString, tyOpenArray, tyVarargs}:
|
{tySequence, tyString, tyCString, tyOpenArray, tyVarargs}:
|
||||||
result = newIntNodeT(lastOrd(g.config, skipTypes(n[1].typ, abstractVar)), n, g)
|
result = newIntNodeT(lastOrd(g.config, skipTypes(n[1].typ, abstractVar)), n, g)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -615,7 +615,7 @@ proc firstOrd*(conf: ConfigRef; t: PType): BiggestInt =
|
||||||
else:
|
else:
|
||||||
assert(t.n.sons[0].kind == nkSym)
|
assert(t.n.sons[0].kind == nkSym)
|
||||||
result = t.n.sons[0].sym.position
|
result = t.n.sons[0].sym.position
|
||||||
of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tyStatic, tyInferred:
|
of tyGenericInst, tyDistinct, tyTypeDesc, tyAlias, tyStatic, tyInferred, tyUserTypeClassInst:
|
||||||
result = firstOrd(conf, lastSon(t))
|
result = firstOrd(conf, lastSon(t))
|
||||||
of tyOrdinal:
|
of tyOrdinal:
|
||||||
if t.len > 0: result = firstOrd(conf, lastSon(t))
|
if t.len > 0: result = firstOrd(conf, lastSon(t))
|
||||||
|
|
|
||||||
31
tests/concepts/treversable.nim
Normal file
31
tests/concepts/treversable.nim
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# issue 7705, 7703, 7702
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
z
|
||||||
|
e
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
Reversable*[T] = concept a
|
||||||
|
a[int] is T
|
||||||
|
a.high is int
|
||||||
|
a.len is int
|
||||||
|
a.low is int
|
||||||
|
|
||||||
|
proc get[T](s: Reversable[T], n: int): T =
|
||||||
|
s[n]
|
||||||
|
|
||||||
|
proc hi[T](s: Reversable[T]): int =
|
||||||
|
s.high
|
||||||
|
|
||||||
|
proc lo[T](s: Reversable[T]): int =
|
||||||
|
s.low
|
||||||
|
|
||||||
|
iterator reverse*[T](s: Reversable[T]): T =
|
||||||
|
assert hi(s) - lo(s) == len(s) - 1
|
||||||
|
for z in hi(s).countdown(lo(s)):
|
||||||
|
yield s.get(z)
|
||||||
|
|
||||||
|
for s in @["e", "z"].reverse:
|
||||||
|
echo s
|
||||||
Loading…
Add table
Add a link
Reference in a new issue