From 754e2ef1db61610cba1b96752fa37c6e923e2808 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Mon, 30 Dec 2013 19:11:42 +0200 Subject: [PATCH] migrate the static param handling to ReplaceTypeVars; fix tgenericvariant --- compiler/sem.nim | 11 +++++++---- compiler/semtypes.nim | 23 +++++++++++++++++------ compiler/semtypinst.nim | 21 ++++++++++----------- compiler/sigmatch.nim | 3 +-- compiler/types.nim | 4 ++-- tests/reject/teffects1.nim | 2 +- 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/compiler/sem.nim b/compiler/sem.nim index df37a6384f..e9c2de6572 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -204,12 +204,15 @@ proc tryConstExpr(c: PContext, n: PNode): PNode = result = getConstExpr(c.module, e) if result != nil: return - result = evalConstExpr(c.module, e) - if result == nil or result.kind == nkEmpty: + try: + result = evalConstExpr(c.module, e) + if result == nil or result.kind == nkEmpty: + return nil + + result = fixupTypeAfterEval(c, result, e) + except: return nil - result = fixupTypeAfterEval(c, result, e) - proc semConstExpr(c: PContext, n: PNode): PNode = var e = semExprWithType(c, n) if e == nil: diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 175901057d..fb05469615 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -594,7 +594,7 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) = let typedescId = getIdent"typedesc" template shouldHaveMeta(t) = - InternalAssert tfHasMeta in result.lastSon.flags + InternalAssert tfHasMeta in t.flags # result.lastSon.flags.incl tfHasMeta proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode, @@ -677,7 +677,8 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode, result = newTypeS(tyGenericInvokation, c) result.rawAddSon(paramType) for i in 0 .. paramType.sonsLen - 2: - result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true)) + result.rawAddSon newTypeS(tyAnything, c) + # result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true)) result = instGenericContainer(c, paramType.sym.info, result, allowMetaTypes = true) result.lastSon.shouldHaveMeta @@ -696,20 +697,29 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode, if liftBody != nil: result = liftBody result.shouldHaveMeta - + + of tyGenericInvokation: + for i in 1 .. 0: result = liftingWalk(paramType.lastSon) else: - result = addImplicitGeneric(newTypeS(tyGenericParam, c)) + result = addImplicitGeneric(newTypeS(tyAnything, c)) else: nil @@ -860,7 +870,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = return newOrPrevType(tyError, prev, c) var isConcrete = true - + for i in 1 ..