fixes tcompiletimerange [bugfix] (#11720)

This commit is contained in:
Andreas Rumpf
2019-07-12 15:37:54 +02:00
committed by GitHub
parent 38b836b49e
commit 2895ad70c8
3 changed files with 29 additions and 7 deletions

View File

@@ -1379,8 +1379,11 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
if tx.isNil or isTupleRecursive(tx):
localError(c.config, n.info, "illegal recursion in type '$1'" % typeToString(result[0]))
return errorType(c)
if tx != result and tx.kind == tyObject and tx.sons[0] != nil:
semObjectTypeForInheritedGenericInst(c, n, tx)
if tx != result and tx.kind == tyObject:
if tx.sons[0] != nil:
semObjectTypeForInheritedGenericInst(c, n, tx)
var position = 0
recomputeFieldPositions(tx, tx.n, position)
proc maybeAliasType(c: PContext; typeExpr, prev: PType): PType =
if typeExpr.kind in {tyObject, tyEnum, tyDistinct, tyForward} and prev != nil:

View File

@@ -667,6 +667,22 @@ proc replaceTypesForLambda*(p: PContext, pt: TIdTable, n: PNode;
result = replaceTypeVarsN(cl, n)
popInfoContext(p.config)
proc recomputeFieldPositions*(t: PType; obj: PNode; currPosition: var int) =
if t != nil and t.len > 0 and t.sons[0] != nil:
let b = skipTypes(t.sons[0], skipPtrs)
recomputeFieldPositions(b, b.n, currPosition)
case obj.kind
of nkRecList:
for i in 0 ..< sonsLen(obj): recomputeFieldPositions(nil, obj.sons[i], currPosition)
of nkRecCase:
recomputeFieldPositions(nil, obj.sons[0], currPosition)
for i in 1 ..< sonsLen(obj):
recomputeFieldPositions(nil, lastSon(obj.sons[i]), currPosition)
of nkSym:
obj.sym.position = currPosition
inc currPosition
else: discard "cannot happen"
proc generateTypeInstance*(p: PContext, pt: TIdTable, info: TLineInfo,
t: PType): PType =
var typeMap = initLayeredTypeMap(pt)
@@ -674,6 +690,10 @@ proc generateTypeInstance*(p: PContext, pt: TIdTable, info: TLineInfo,
pushInfoContext(p.config, info)
result = replaceTypeVarsT(cl, t)
popInfoContext(p.config)
let objType = result.skipTypes(abstractInst)
if objType.kind == tyObject:
var position = 0
recomputeFieldPositions(objType, objType.n, position)
proc prepareMetatypeForSigmatch*(p: PContext, pt: TIdTable, info: TLineInfo,
t: PType): PType =

View File

@@ -1,18 +1,17 @@
discard """
disabled: "true"
"""
# issue #8199
const rangesGCHoldEnabled = not defined(rangesDisableGCHold)
const rangesGCHoldEnabled = true # not defined(rangesDisableGCHold)
type
# A view into immutable array
Range*[T] {.shallow.} = object
when rangesGCHoldEnabled:
gcHold: seq[T]
start: ptr T
mLen: int32
gcHold: seq[T] # 0
start: ptr T # 1
mLen: int32 # 2
type
BytesRange* = Range[byte]