diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index c8f2c26874ad..abdd2c868b89 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1709,7 +1709,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit traverse(stats ++ rest) case stat :: rest => val stat1 = typed(stat)(ctx.exprContext(stat, exprOwner)) - if (!ctx.isAfterTyper && isPureExpr(stat1)) + if (!ctx.isAfterTyper && isPureExpr(stat1) && !stat1.tpe.isRef(defn.UnitClass)) ctx.warning(em"a pure expression does nothing in statement position", stat.pos) buf += stat1 traverse(rest) diff --git a/tests/neg/customArgs/xfatalWarnings.scala b/tests/neg/customArgs/xfatalWarnings.scala index 86ca7ed8f4dc..862b94039e2a 100644 --- a/tests/neg/customArgs/xfatalWarnings.scala +++ b/tests/neg/customArgs/xfatalWarnings.scala @@ -4,4 +4,8 @@ object xfatalWarnings { opt match { // error when running with -Xfatal-warnings case None => } -} \ No newline at end of file + + object Test { + while (true) {} // should be ok. no "pure expression does nothing in statement position" issued. + } +}