This commit is contained in:
Araq
2015-04-11 02:28:06 +02:00
parent 670367e13b
commit d89a20cc1d
6 changed files with 54 additions and 2 deletions

View File

@@ -503,6 +503,7 @@ proc gsub(g: var TSrcGen, n: PNode) =
proc hasCom(n: PNode): bool =
result = false
if n.isNil: return false
if n.comment != nil: return true
case n.kind
of nkEmpty..nkNilLit: discard

View File

@@ -176,7 +176,9 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
for i in 1 .. <result.len:
# twrong_field_caching requires these 'resetIdTable' calls:
if i > 1: resetIdTable(cl.symMap)
if i > 1:
resetIdTable(cl.symMap)
resetIdTable(cl.localCache)
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
propagateToOwner(result, result.sons[i])
internalAssert originalParams[i].kind == nkSym
@@ -196,6 +198,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
addDecl(c, result.n.sons[i].sym)
resetIdTable(cl.symMap)
resetIdTable(cl.localCache)
result.sons[0] = replaceTypeVarsT(cl, result.sons[0])
result.n.sons[0] = originalParams[0].copyTree

View File

@@ -764,7 +764,7 @@ proc track(tracked: PEffects, n: PNode) =
setLen(tracked.locked, oldLocked)
tracked.currLockLevel = oldLockLevel
of nkTypeSection, nkProcDef, nkConverterDef, nkMethodDef, nkIteratorDef,
nkMacroDef, nkTemplateDef:
nkMacroDef, nkTemplateDef, nkLambda, nkDo:
discard
else:
for i in 0 .. <safeLen(n): track(tracked, n.sons[i])

View File

@@ -418,15 +418,23 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
result = t
of tyGenericInst:
result = PType(idTableGet(cl.localCache, t))
if result != nil: return result
result = instCopyType(cl, t)
idTablePut(cl.localCache, t, result)
for i in 1 .. <result.sonsLen:
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
propagateToOwner(result, result.lastSon)
else:
if containsGenericType(t):
#if not cl.allowMetaTypes:
result = PType(idTableGet(cl.localCache, t))
if result != nil: return result
result = instCopyType(cl, t)
result.size = -1 # needs to be recomputed
#if not cl.allowMetaTypes:
idTablePut(cl.localCache, t, result)
for i in countup(0, sonsLen(result) - 1):
if result.sons[i] != nil:

View File

@@ -0,0 +1,21 @@
discard """
errormsg: "cannot instantiate: 'GenericNodeObj'"
line: 21
"""
# bug #2509
type
GenericNodeObj[T] = ref object
obj: T
Node* = ref object
children*: seq[Node]
parent*: Node
nodeObj*: GenericNodeObj # [int]
proc newNode*(nodeObj: GenericNodeObj): Node =
result = Node(nodeObj: nodeObj)
newSeq(result.children, 10)
var genericObj = GenericNodeObj[int]()
var myNode = newNode(genericObj)

View File

@@ -0,0 +1,19 @@
# bug #2508
type
GenericNodeObj[T] = ref object
obj: T
Node* = ref object
children*: seq[Node]
parent*: Node
nodeObj*: GenericNodeObj[int]
proc newNode*(nodeObj: GenericNodeObj): Node =
result = Node(nodeObj: nodeObj)
newSeq(result.children, 10)
var genericObj = GenericNodeObj[int]()
var myNode = newNode(genericObj)