Skip to content

Refine purity check #2837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion tests/neg/customArgs/xfatalWarnings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ object xfatalWarnings {
opt match { // error when running with -Xfatal-warnings
case None =>
}
}

object Test {
while (true) {} // should be ok. no "pure expression does nothing in statement position" issued.
}
}