From a102eb5ef653a71e4286312ff9027d37b814a2f6 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 16 Mar 2020 12:54:31 +0100 Subject: fixes #13646 --- compiler/semexprs.nim | 12 +++++++++--- compiler/semtypinst.nim | 3 +++ tests/metatype/tmetatype_various.nim | 25 ++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index f75642bcb..a479327be 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -232,13 +232,14 @@ proc semConv(c: PContext, n: PNode): PNode = result = newNodeI(nkConv, n.info) var targetType = semTypeNode(c, n[0], nil) - if targetType.kind == tyTypeDesc: + case targetType.kind + of tyTypeDesc: internalAssert c.config, targetType.len > 0 if targetType.base.kind == tyNone: return semTypeOf(c, n) else: targetType = targetType.base - elif targetType.kind == tyStatic: + of tyStatic: var evaluated = semStaticExpr(c, n[1]) if evaluated.kind == nkType or evaluated.typ.kind == tyTypeDesc: result = n @@ -248,6 +249,7 @@ proc semConv(c: PContext, n: PNode): PNode = return evaluated else: targetType = targetType.base + else: discard maybeLiftType(targetType, c, n[0].info) @@ -268,7 +270,7 @@ proc semConv(c: PContext, n: PNode): PNode = targetType.skipTypes(abstractPtrs).kind == tyObject: localError(c.config, n.info, "object construction uses ':', not '='") var op = semExprWithType(c, n[1]) - if targetType.isMetaType: + if targetType.kind != tyGenericParam and targetType.isMetaType: let final = inferWithMetatype(c, targetType, op, true) result.add final result.typ = final.typ @@ -279,6 +281,10 @@ proc semConv(c: PContext, n: PNode): PNode = # here or needs to be overwritten too then. result.add op + if targetType.kind == tyGenericParam: + result.typ = makeTypeFromExpr(c, copyTree(result)) + return result + if not isSymChoice(op): let status = checkConvertible(c, result.typ, op) case status diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index d3ab9d866..5aec3eed9 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -618,6 +618,9 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType = eraseVoidParams(result) skipIntLiteralParams(result) + of tyRange: + result[0] = result[0].skipTypes({tyStatic, tyDistinct}) + else: discard else: # If this type doesn't refer to a generic type we may still want to run it diff --git a/tests/metatype/tmetatype_various.nim b/tests/metatype/tmetatype_various.nim index a56eca018..0dd948293 100644 --- a/tests/metatype/tmetatype_various.nim +++ b/tests/metatype/tmetatype_various.nim @@ -1,4 +1,7 @@ - +discard """ + output: '''[1, 0, 0, 0, 0, 0, 0, 0] + CTBool[Ct[system.uint32]]''' +""" block tconstraints: proc myGenericProc[T: object|tuple|int|ptr|ref|distinct](x: T): string = @@ -37,13 +40,29 @@ block tfieldaccessor: block tprocbothmeta: proc myFun[A](x: A): auto = result = float(x+10) - + proc myMap[T,S](sIn: seq[T], f: proc (q: T): S): seq[S] = result = newSeq[S](sIn.len) for i in 0..