Skip to content

Commit dba4b94

Browse files
committed
Avoid cycle when computing sets
The tightened subtyping algorithm led to a cycle in baseTypeRef when compiling sets.scala. This commit fixes the problem.
1 parent 2703543 commit dba4b94

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,18 @@ object Types {
447447
if (rinfo.isAlias) rinfo
448448
else if (pdenot.info.isAlias) pdenot.info
449449
else if (ctx.pendingMemberSearches.contains(name)) safeAnd(pdenot.info, rinfo)
450-
else pdenot.info & rinfo
450+
else
451+
try pdenot.info & rinfo
452+
catch {
453+
case ex: CyclicReference =>
454+
// happens for tests/pos/sets.scala. findMember is called from baseTypeRef.
455+
// The & causes a subtype check which calls baseTypeRef again with the same
456+
// superclass. In the observed case, the superclass was Any, and
457+
// the special shortcut for Any in derivesFrom was as yet absent. To reproduce,
458+
// remove the special treatment of Any in derivesFrom and compile
459+
// sets.scala.
460+
safeAnd(pdenot.info, rinfo)
461+
}
451462
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
452463
} else
453464
pdenot & (new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId)), pre)
@@ -1562,6 +1573,15 @@ object Types {
15621573
case _ =>
15631574
false
15641575
}
1576+
1577+
/* A version of toString which also prints aliases. Can be used for debugging
1578+
override def toString =
1579+
if (isTerm) s"TermRef($prefix, $name)"
1580+
else s"TypeRef($prefix, $name)${
1581+
if (lastDenotation != null && lastDenotation.infoOrCompleter.isAlias)
1582+
s"@@@ ${lastDenotation.infoOrCompleter.asInstanceOf[TypeAlias].hi}"
1583+
else ""}"
1584+
*/
15651585
}
15661586

15671587
abstract case class TermRef(override val prefix: Type, name: TermName) extends NamedType with SingletonType {

0 commit comments

Comments
 (0)