fix #6277
This commit is contained in:
parent
70380882c5
commit
057d5789ba
2 changed files with 21 additions and 1 deletions
|
|
@ -849,7 +849,7 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) =
|
||||||
var a, b: TLoc
|
var a, b: TLoc
|
||||||
initLocExpr(p, x, a)
|
initLocExpr(p, x, a)
|
||||||
initLocExpr(p, y, b)
|
initLocExpr(p, y, b)
|
||||||
var ty = skipTypes(skipTypes(a.t, abstractVarRange), abstractPtrs)
|
var ty = skipTypes(a.t, abstractVarRange + abstractPtrs + tyUserTypeClasses)
|
||||||
var first = intLiteral(firstOrd(ty))
|
var first = intLiteral(firstOrd(ty))
|
||||||
# emit range check:
|
# emit range check:
|
||||||
if optBoundsCheck in p.options and tfUncheckedArray notin ty.flags:
|
if optBoundsCheck in p.options and tfUncheckedArray notin ty.flags:
|
||||||
|
|
|
||||||
20
tests/concepts/titerable.nim
Normal file
20
tests/concepts/titerable.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
discard """
|
||||||
|
nimout: "int\nint"
|
||||||
|
output: 15
|
||||||
|
"""
|
||||||
|
|
||||||
|
import typetraits
|
||||||
|
|
||||||
|
type
|
||||||
|
Iterable[T] = concept x
|
||||||
|
for value in x:
|
||||||
|
type(value) is T
|
||||||
|
|
||||||
|
proc sum*[T](iter: Iterable[T]): T =
|
||||||
|
static: echo T.name
|
||||||
|
for element in iter:
|
||||||
|
static: echo element.type.name
|
||||||
|
result += element
|
||||||
|
|
||||||
|
echo sum([1, 2, 3, 4, 5])
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue