diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index 4ba6643ecf..6dfd7b52c3 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -99,7 +99,10 @@ proc getUniqueType*(key: PType): PType = gCanonicalTypes[k] = key result = key of tyTypeDesc, tyTypeClasses, tyGenericParam, tyFromExpr, tyFieldAccessor: - internalError("getUniqueType") + if key.sym != nil: + internalError(key.sym.info, "metatype not eliminated") + else: + internalError("metatype not eliminated") of tyDistinct: if key.deepCopy != nil: result = key else: result = getUniqueType(lastSon(key)) diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 9c9281da01..48d725ea88 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -234,7 +234,7 @@ proc semGenericStmt(c: PContext, n: PNode, discard of skProc, skMethod, skIterators, skConverter, skModule: result.sons[0] = symChoice(c, fn, s, scOption) - # do check of 's.magic==mRoof' here because it might be some + # do not check of 's.magic==mRoof' here because it might be some # other '^' but after overload resolution the proper one: if ctx.bracketExpr != nil and n.len == 2 and s.name.s == "^": result.add ctx.bracketExpr diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 64e3e8cb85..1c1d71a2f6 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -164,7 +164,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable, addDecl(c, prc) pushInfoContext(info) - var cl = initTypeVars(c, pt, info) + var cl = initTypeVars(c, pt, info, nil) var result = instCopyType(cl, prc.typ) let originalParams = result.n result.n = originalParams.shallowCopy diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index f67ee2822a..adb1c81c11 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -957,27 +957,35 @@ proc semDo(c: PContext, n: PNode, flags: TExprFlags): PNode = proc semInferredLambda(c: PContext, pt: TIdTable, n: PNode): PNode = var n = n - n = replaceTypesInBody(c, pt, n) + let original = n.sons[namePos].sym + let s = copySym(original, false) + incl(s.flags, sfFromGeneric) + + n = replaceTypesInBody(c, pt, n, original) result = n - + s.ast = result + n.sons[namePos].sym = s n.sons[genericParamsPos] = emptyNode - n.sons[paramsPos] = n.typ.n - + let params = n.typ.n + n.sons[paramsPos] = params + s.typ = n.typ + for i in 1.. U): U = + result = v + for x in lst: + result = f(x, result) + +proc mean[T: SomeNumber](xs: seq[T]): T = + xs.foldRight(0.T, (xBAZ: auto, yBAZ: auto) => xBAZ + yBAZ) / T(xs.len) + +when isMainModule: + let x = mean(@[1.float, 2, 3]) + echo x +