Skip to content

Commit 054c53d

Browse files
committed
Simplifications
It turns out that now that we know that cyclic evaluations of LazyRefs can happen in normal code, we can just use a CyclicReference for them. There's no need to label this case with a different exception.
1 parent eb55a3d commit 054c53d

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,14 +1029,10 @@ object Types {
10291029
*/
10301030
def recoverable_&(that: Type)(using Context): Type =
10311031
try this & that
1032-
catch {
1033-
case ex: CyclicReference => this safe_& that
1034-
// A test case where this happens is tests/pos/i536.scala.
1035-
// The & causes a subtype check which calls baseTypeRef again with the same
1036-
// superclass.
1037-
case ex: LazyRefCycle => this safe_& that
1038-
// A test case where this happens is tests/pos/i9364.scala
1039-
}
1032+
catch case ex: CyclicReference => this safe_& that
1033+
// A test case where this happens is tests/pos/i536.scala.
1034+
// The & causes a subtype check which calls baseTypeRef again with the same
1035+
// superclass.
10401036

10411037
def | (that: Type)(using Context): Type = {
10421038
record("|")
@@ -2643,12 +2639,9 @@ object Types {
26432639
def ref(using Context): Type =
26442640
if computed then
26452641
if myRef == null then
2646-
// if errors were reported previously handle this by throwing a CyclicReference
2647-
// instead of crashing immediately. A test case is neg/i6057.scala.
2648-
if reportCycles || ctx.reporter.errorsReported then
2649-
throw CyclicReference(NoDenotation) // recoverable
2650-
else
2651-
throw LazyRefCycle() // generally not recoverable, but there are a few exceptions
2642+
throw CyclicReference(NoDenotation)
2643+
// i9346.scala shows that such cycles can arise in normal code
2644+
// when trying to compute asSeenFrom on refined types.
26522645
else
26532646
computed = true
26542647
val result = refFn
@@ -2674,8 +2667,6 @@ object Types {
26742667
override def hashCode: Int = System.identityHashCode(this)
26752668
}
26762669

2677-
class LazyRefCycle extends Error("Illegal cycle: LazyRef depends on itself")
2678-
26792670
// --- Refined Type and RecType ------------------------------------------------
26802671

26812672
abstract class RefinedOrRecType extends CachedProxyType with ValueType {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ object Variances {
118118
lam.typeParams(t.paramNum).storedVariance &= varianceFromInt(variance)
119119
case t: LazyRef =>
120120
try traverse(t.ref)
121-
catch case _: LazyRefCycle =>
121+
catch case _: CyclicReference =>
122122
() // can happen with deeply entangled F-bounds, such as in i9364.scala under -Ytest-pickler
123123
case _ =>
124124
traverseChildren(t)

0 commit comments

Comments
 (0)