File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff 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 =>
Original file line number Diff line number Diff line change 11class IOCapability
22
33object 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)
You can’t perform that action at this time.
0 commit comments