Skip to content

Commit 70eaa36

Browse files
committed
Fix condition where to check for pure expressions
1 parent df755d8 commit 70eaa36

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,8 +1708,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
17081708
traverse(stats ++ rest)
17091709
case stat :: rest =>
17101710
val stat1 = typed(stat)(ctx.exprContext(stat, exprOwner))
1711-
if ((ctx.owner.isType || rest.nonEmpty) && isPureExpr(stat1) && !ctx.isAfterTyper)
1712-
ctx.warning(em"a pure expression does nothing in statement position", stat1.pos)
1711+
if (!ctx.isAfterTyper && isPureExpr(stat1))
1712+
ctx.warning(em"a pure expression does nothing in statement position", stat.pos)
17131713
buf += stat1
17141714
traverse(rest)
17151715
case nil =>

tests/neg/customArgs/pureStatement.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
class IOCapability
22

33
object Test {
4+
"" // error: pure expression does nothing in statement position
5+
6+
locally {
7+
"" // error: pure expression does nothing in statement position
8+
9+
println("")
10+
11+
42 // error: pure expression does nothing in statement position
12+
13+
((x: Int) => println("hi")) // error: pure expression does nothing in statement position
14+
15+
()
16+
}
17+
418
// Forgot to mark `ev` implicit!
519
def doSideEffects(x: Int)(ev: IOCapability) = {
620
println("x: " + x)

0 commit comments

Comments
 (0)