From 057d5789ba6cf7e1f0cef681ffba77b0c4788110 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sat, 7 Oct 2017 22:17:16 +0300 Subject: [PATCH] fix #6277 --- compiler/ccgexprs.nim | 2 +- tests/concepts/titerable.nim | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/concepts/titerable.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index dd526c5fb..da92b281e 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -849,7 +849,7 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) = var a, b: TLoc initLocExpr(p, x, a) 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)) # emit range check: if optBoundsCheck in p.options and tfUncheckedArray notin ty.flags: diff --git a/tests/concepts/titerable.nim b/tests/concepts/titerable.nim new file mode 100644 index 000000000..b18658b2a --- /dev/null +++ b/tests/concepts/titerable.nim @@ -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]) +