File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -1707,7 +1707,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1707
1707
case Thicket (stats) :: rest =>
1708
1708
traverse(stats ++ rest)
1709
1709
case stat :: rest =>
1710
- buf += typed(stat)(ctx.exprContext(stat, exprOwner))
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)
1713
+ buf += stat1
1711
1714
traverse(rest)
1712
1715
case nil =>
1713
1716
buf.toList
Original file line number Diff line number Diff line change @@ -163,6 +163,7 @@ class CompilationTests extends ParallelTesting {
163
163
compileFile(" ../tests/neg/customArgs/noimports2.scala" , defaultOptions.and(" -Yno-imports" )) +
164
164
compileFile(" ../tests/neg/customArgs/overloadsOnAbstractTypes.scala" , allowDoubleBindings) +
165
165
compileFile(" ../tests/neg/customArgs/xfatalWarnings.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
166
+ compileFile(" ../tests/neg/customArgs/pureStatement.scala" , defaultOptions.and(" -Xfatal-warnings" )) +
166
167
compileFile(" ../tests/neg/customArgs/phantom-overload.scala" , allowDoubleBindings) +
167
168
compileFile(" ../tests/neg/tailcall/t1672b.scala" , defaultOptions) +
168
169
compileFile(" ../tests/neg/tailcall/t3275.scala" , defaultOptions) +
Original file line number Diff line number Diff line change
1
+ class IOCapability
2
+
3
+ object Test {
4
+ // Forgot to mark `ev` implicit!
5
+ def doSideEffects (x : Int )(ev : IOCapability ) = {
6
+ println(" x: " + x)
7
+ }
8
+
9
+ implicit val cap : IOCapability = new IOCapability
10
+
11
+ 2 // error: pure expression does nothing in statement position
12
+
13
+ doSideEffects(1 ) // error: pure expression does nothing in statement position
14
+ }
You can’t perform that action at this time.
0 commit comments