Skip to content

Commit 1b2fc1f

Browse files
committed
Don't force in isErronous check
isErroneous forced LazyRefs through the `existsPart` combinator. This might prompt further errors or infinite recursions, so should be avoided. Seen in the wild when trying to trace t1756.scala with -Ylog:front and typr printer on.
1 parent ac423a3 commit 1b2fc1f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ object Types {
177177
}
178178

179179
/** Is some part of this type produced as a repair for an error? */
180-
final def isErroneous(implicit ctx: Context): Boolean = existsPart(_.isError)
180+
final def isErroneous(implicit ctx: Context): Boolean = existsPart(_.isError, forceLazy = false)
181181

182182
/** Does the type carry an annotation that is an instance of `cls`? */
183183
final def hasAnnotation(cls: ClassSymbol)(implicit ctx: Context): Boolean = stripTypeVar match {
@@ -219,8 +219,8 @@ object Types {
219219

220220
/** Returns true if there is a part of this type that satisfies predicate `p`.
221221
*/
222-
final def existsPart(p: Type => Boolean)(implicit ctx: Context): Boolean =
223-
new ExistsAccumulator(p).apply(false, this)
222+
final def existsPart(p: Type => Boolean, forceLazy: Boolean = true)(implicit ctx: Context): Boolean =
223+
new ExistsAccumulator(p, forceLazy).apply(false, this)
224224

225225
/** Returns true if all parts of this type satisfy predicate `p`.
226226
*/
@@ -3688,9 +3688,10 @@ object Types {
36883688
protected def traverseChildren(tp: Type) = foldOver((), tp)
36893689
}
36903690

3691-
class ExistsAccumulator(p: Type => Boolean)(implicit ctx: Context) extends TypeAccumulator[Boolean] {
3691+
class ExistsAccumulator(p: Type => Boolean, forceLazy: Boolean = true)(implicit ctx: Context) extends TypeAccumulator[Boolean] {
36923692
override def stopAtStatic = false
3693-
def apply(x: Boolean, tp: Type) = x || p(tp) || foldOver(x, tp)
3693+
def apply(x: Boolean, tp: Type) =
3694+
x || p(tp) || (forceLazy || !tp.isInstanceOf[LazyRef]) && foldOver(x, tp)
36943695
}
36953696

36963697
class ForeachAccumulator(p: Type => Unit)(implicit ctx: Context) extends TypeAccumulator[Unit] {

0 commit comments

Comments
 (0)