fixes #2509
This commit is contained in:
parent
670367e13b
commit
d89a20cc1d
6 changed files with 54 additions and 2 deletions
|
|
@ -503,6 +503,7 @@ proc gsub(g: var TSrcGen, n: PNode) =
|
||||||
|
|
||||||
proc hasCom(n: PNode): bool =
|
proc hasCom(n: PNode): bool =
|
||||||
result = false
|
result = false
|
||||||
|
if n.isNil: return false
|
||||||
if n.comment != nil: return true
|
if n.comment != nil: return true
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkEmpty..nkNilLit: discard
|
of nkEmpty..nkNilLit: discard
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,9 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
|
|
||||||
for i in 1 .. <result.len:
|
for i in 1 .. <result.len:
|
||||||
# twrong_field_caching requires these 'resetIdTable' calls:
|
# 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])
|
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
|
||||||
propagateToOwner(result, result.sons[i])
|
propagateToOwner(result, result.sons[i])
|
||||||
internalAssert originalParams[i].kind == nkSym
|
internalAssert originalParams[i].kind == nkSym
|
||||||
|
|
@ -196,6 +198,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
addDecl(c, result.n.sons[i].sym)
|
addDecl(c, result.n.sons[i].sym)
|
||||||
|
|
||||||
resetIdTable(cl.symMap)
|
resetIdTable(cl.symMap)
|
||||||
|
resetIdTable(cl.localCache)
|
||||||
result.sons[0] = replaceTypeVarsT(cl, result.sons[0])
|
result.sons[0] = replaceTypeVarsT(cl, result.sons[0])
|
||||||
result.n.sons[0] = originalParams[0].copyTree
|
result.n.sons[0] = originalParams[0].copyTree
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -764,7 +764,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
setLen(tracked.locked, oldLocked)
|
setLen(tracked.locked, oldLocked)
|
||||||
tracked.currLockLevel = oldLockLevel
|
tracked.currLockLevel = oldLockLevel
|
||||||
of nkTypeSection, nkProcDef, nkConverterDef, nkMethodDef, nkIteratorDef,
|
of nkTypeSection, nkProcDef, nkConverterDef, nkMethodDef, nkIteratorDef,
|
||||||
nkMacroDef, nkTemplateDef:
|
nkMacroDef, nkTemplateDef, nkLambda, nkDo:
|
||||||
discard
|
discard
|
||||||
else:
|
else:
|
||||||
for i in 0 .. <safeLen(n): track(tracked, n.sons[i])
|
for i in 0 .. <safeLen(n): track(tracked, n.sons[i])
|
||||||
|
|
|
||||||
|
|
@ -418,15 +418,23 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
result = t
|
result = t
|
||||||
|
|
||||||
of tyGenericInst:
|
of tyGenericInst:
|
||||||
|
result = PType(idTableGet(cl.localCache, t))
|
||||||
|
if result != nil: return result
|
||||||
result = instCopyType(cl, t)
|
result = instCopyType(cl, t)
|
||||||
|
idTablePut(cl.localCache, t, result)
|
||||||
for i in 1 .. <result.sonsLen:
|
for i in 1 .. <result.sonsLen:
|
||||||
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
|
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
|
||||||
propagateToOwner(result, result.lastSon)
|
propagateToOwner(result, result.lastSon)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if containsGenericType(t):
|
if containsGenericType(t):
|
||||||
|
#if not cl.allowMetaTypes:
|
||||||
|
result = PType(idTableGet(cl.localCache, t))
|
||||||
|
if result != nil: return result
|
||||||
result = instCopyType(cl, t)
|
result = instCopyType(cl, t)
|
||||||
result.size = -1 # needs to be recomputed
|
result.size = -1 # needs to be recomputed
|
||||||
|
#if not cl.allowMetaTypes:
|
||||||
|
idTablePut(cl.localCache, t, result)
|
||||||
|
|
||||||
for i in countup(0, sonsLen(result) - 1):
|
for i in countup(0, sonsLen(result) - 1):
|
||||||
if result.sons[i] != nil:
|
if result.sons[i] != nil:
|
||||||
|
|
|
||||||
21
tests/generics/twrong_generic_object.nim
Normal file
21
tests/generics/twrong_generic_object.nim
Normal 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)
|
||||||
19
tests/objects/trefobjsyntax2.nim
Normal file
19
tests/objects/trefobjsyntax2.nim
Normal 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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue