Skip to content

Commit 433541f

Browse files
committed
Improve cycle detection
Cycles can also arise for initialized type refs that appear in their own types.
1 parent 368bc2e commit 433541f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ object Checking {
130130
*/
131131
class CheckNonCyclicMap(sym: Symbol, reportErrors: Boolean)(implicit ctx: Context) extends TypeMap {
132132

133+
/** Set of type references whose info is currently checked */
134+
private val locked = mutable.Set[TypeRef]()
135+
133136
/** Are cycles allowed within nested refinedInfos of currently checked type? */
134137
private var nestedCycleOK = false
135138

@@ -212,7 +215,10 @@ object Checking {
212215
}
213216
if (isInteresting(pre)) {
214217
val pre1 = this(pre, false, false)
215-
checkInfo(tp.info)
218+
if (locked.contains(tp)) throw CyclicReference(tp.symbol)
219+
locked += tp
220+
try checkInfo(tp.info)
221+
finally locked -= tp
216222
if (pre1 eq pre) tp else tp.newLikeThis(pre1)
217223
}
218224
else tp

0 commit comments

Comments
 (0)