Skip to content

Commit 8f039a4

Browse files
committed
Do widening directly in isErroneous
1 parent 47a270d commit 8f039a4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,12 @@ object Types {
284284
/** Is this type produced as a repair for an error? */
285285
final def isError(implicit ctx: Context): Boolean = stripTypeVar.isInstanceOf[ErrorType]
286286

287-
/** Is some part of this type produced as a repair for an error? */
288-
def isErroneous(implicit ctx: Context): Boolean = existsPart(_.isError, forceLazy = false)
287+
/** Is some part of this type (or of an underlying type of this type) produced as a repair for an error? */
288+
def isErroneous(implicit ctx: Context): Boolean =
289+
existsPart(_.isError, forceLazy = false) || {
290+
val tpw = this.widen
291+
(tpw `ne` this) && tpw.isErroneous
292+
}
289293

290294
/** Does the type carry an annotation that is an instance of `cls`? */
291295
@tailrec final def hasAnnotation(cls: ClassSymbol)(implicit ctx: Context): Boolean = stripTypeVar match {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,7 @@ class Typer extends Namer
28972897
}
28982898

28992899
private def checkStatementPurity(tree: tpd.Tree)(original: untpd.Tree, exprOwner: Symbol)(implicit ctx: Context): Unit = {
2900-
if (!tree.tpe.widen.isErroneous && !ctx.isAfterTyper && isPureExpr(tree) &&
2900+
if (!tree.tpe.isErroneous && !ctx.isAfterTyper && isPureExpr(tree) &&
29012901
!tree.tpe.isRef(defn.UnitClass) && !isSelfOrSuperConstrCall(tree))
29022902
ctx.warning(PureExpressionInStatementPosition(original, exprOwner), original.sourcePos)
29032903
}

0 commit comments

Comments
 (0)