Skip to content

Commit

Permalink
fixes #13763
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Mar 27, 2020
1 parent 289b31e commit ee7bff3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,10 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
else:
while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0:
x = x.lastSon
# we need the 'safeSkipTypes' here because illegally recursive types
# can enter at this point, see bug #13763
if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty} and
s.typ.skipTypes(abstractPtrs-{tyAlias}).kind notin {tyObject, tyEnum}:
s.typ.safeSkipTypes(abstractPtrs).kind notin {tyObject, tyEnum}:
# type aliases are hard:
var t = semTypeNode(c, x, nil)
assert t != nil
Expand Down
7 changes: 7 additions & 0 deletions compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,13 @@ proc containsCompileTimeOnly*(t: PType): bool =
return true
return false

proc safeSkipTypes*(t: PType, kinds: TTypeKinds): PType =
## same as 'skipTypes' but with a simple cycle detector.
result = t
var seen = initIntSet()
while result.kind in kinds and not containsOrIncl(seen, result.id):
result = lastSon(result)

type
OrdinalType* = enum
NoneLike, IntLike, FloatLike
Expand Down

0 comments on commit ee7bff3

Please sign in to comment.