Skip to content

Commit b8edc55

Browse files
authored
Merge pull request #2837 from dotty-staging/change-purity-check
Refine purity check
2 parents b791979 + fa45bd3 commit b8edc55

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
17111711
traverse(stats ++ rest)
17121712
case stat :: rest =>
17131713
val stat1 = typed(stat)(ctx.exprContext(stat, exprOwner))
1714-
if (!ctx.isAfterTyper && isPureExpr(stat1))
1714+
if (!ctx.isAfterTyper && isPureExpr(stat1) && !stat1.tpe.isRef(defn.UnitClass))
17151715
ctx.warning(em"a pure expression does nothing in statement position", stat.pos)
17161716
buf += stat1
17171717
traverse(rest)

tests/neg/customArgs/xfatalWarnings.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ object xfatalWarnings {
44
opt match { // error when running with -Xfatal-warnings
55
case None =>
66
}
7-
}
7+
8+
object Test {
9+
while (true) {} // should be ok. no "pure expression does nothing in statement position" issued.
10+
}
11+
}

0 commit comments

Comments
 (0)