Skip to content

Commit b989415

Browse files
authored
Merge pull request #2751 from dotty-staging/add-check-cycles
Detect direct cycles of typerefs referring to themselves
2 parents 717bd99 + d69fb6c commit b989415

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ object Config {
108108
*/
109109
final val checkMethodTypes = false
110110

111+
/** If this flag is set, it is checked that TypeRefs don't refer directly
112+
* to themselves.
113+
*/
114+
final val checkTypeRefCycles = false
115+
111116
/** The recursion depth for showing a summarized string */
112117
final val summarizeDepth = 2
113118

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,18 @@ object Types {
15271527
}
15281528

15291529
/** Hook for adding debug check code when denotations are assigned */
1530-
final def checkDenot()(implicit ctx: Context) = {}
1530+
final def checkDenot()(implicit ctx: Context) =
1531+
if (Config.checkTypeRefCycles)
1532+
lastDenotation match {
1533+
case d: SingleDenotation =>
1534+
d.infoOrCompleter match {
1535+
case TypeBounds(lo, hi) =>
1536+
assert(lo ne this, this)
1537+
assert(hi ne this, this)
1538+
case _ =>
1539+
}
1540+
case _ =>
1541+
}
15311542

15321543
/** A second fallback to recompute the denotation if necessary */
15331544
private def computeDenot(implicit ctx: Context): Denotation = {
@@ -1563,9 +1574,9 @@ object Types {
15631574

15641575
// Don't use setDenot here; double binding checks can give spurious failures after erasure
15651576
lastDenotation = d
1566-
checkDenot()
15671577
lastSymbol = d.symbol
15681578
checkedPeriod = ctx.period
1579+
checkDenot()
15691580
}
15701581
d
15711582
}

0 commit comments

Comments
 (0)