Skip to content

Commit 47a270d

Browse files
committed
Avoid spurious pure expression warning with ErrorTypes
1 parent f4d02de commit 47a270d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

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

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

tests/neg-custom-args/fatal-warnings/pureStatement.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ object Test {
2525
2 // error: pure expression does nothing in statement position
2626

2727
doSideEffects(1) // error: pure expression does nothing in statement position
28+
29+
val broken = new IDontExist("") // error // error
30+
broken.foo // no extra error, and no pure expression warning
31+
broken.foo() // same
2832
}

0 commit comments

Comments
 (0)