Skip to content

Detect direct cycles of typerefs referring to themselves #2751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ object Config {
*/
final val checkMethodTypes = false

/** If this flag is set, it is checked that TypeRefs don't refer directly
* to themselves.
*/
final val checkTypeRefCycles = false

/** The recursion depth for showing a summarized string */
final val summarizeDepth = 2

Expand Down
15 changes: 13 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,18 @@ object Types {
}

/** Hook for adding debug check code when denotations are assigned */
final def checkDenot()(implicit ctx: Context) = {}
final def checkDenot()(implicit ctx: Context) =
if (Config.checkTypeRefCycles)
lastDenotation match {
case d: SingleDenotation =>
d.infoOrCompleter match {
case TypeBounds(lo, hi) =>
assert(lo ne this, this)
assert(hi ne this, this)
case _ =>
}
case _ =>
}

/** A second fallback to recompute the denotation if necessary */
private def computeDenot(implicit ctx: Context): Denotation = {
Expand Down Expand Up @@ -1562,9 +1573,9 @@ object Types {

// Don't use setDenot here; double binding checks can give spurious failures after erasure
lastDenotation = d
checkDenot()
lastSymbol = d.symbol
checkedPeriod = ctx.period
checkDenot()
}
d
}
Expand Down