mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
fixes #2509
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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:
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user