File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -1708,8 +1708,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1708
1708
traverse(stats ++ rest)
1709
1709
case stat :: rest =>
1710
1710
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) {
1712
+ if (isPureExpr(stat1))
1713
+ ctx.warning(em " a pure expression does nothing in statement position " , stat.pos)
1714
+ }
1713
1715
buf += stat1
1714
1716
traverse(rest)
1715
1717
case nil =>
Original file line number Diff line number Diff line change 1
1
class IOCapability
2
2
3
3
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
+
4
18
// Forgot to mark `ev` implicit!
5
19
def doSideEffects (x : Int )(ev : IOCapability ) = {
6
20
println(" x: " + x)
You can’t perform that action at this time.
0 commit comments