diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 350a98fd91..043064d982 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -665,7 +665,9 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) = d.s = OnHeap else: var a: TLoc - let typ = skipTypes(e.sons[0].typ, abstractInst) + var typ = skipTypes(e.sons[0].typ, abstractInst) + if typ.kind in {tyUserTypeClass, tyUserTypeClassInst} and typ.isResolvedUserTypeClass: + typ = typ.lastSon if typ.kind == tyVar and tfVarIsPtr notin typ.flags and p.module.compileToCpp and e.sons[0].kind == nkHiddenAddr: initLocExprSingleUse(p, e[0][0], d) return diff --git a/tests/concepts/t5968.nim b/tests/concepts/t5968.nim new file mode 100644 index 0000000000..adb374c65a --- /dev/null +++ b/tests/concepts/t5968.nim @@ -0,0 +1,20 @@ +discard """ + exitcode: 0 +""" + +type + Enumerable[T] = concept e + for it in e: + it is T + +proc cmap[T, G](e: Enumerable[T], fn: proc(t: T): G): seq[G] = + result = @[] + for it in e: result.add(fn(it)) + +import json + +var x = %["hello", "world"] + +var z = x.cmap(proc(it: JsonNode): string = it.getStr & "!") +assert z == @["hello!", "world!"] +