Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn about any interesting value in statement position. Generalizes the current warning for "pure" expressions.
- Loading branch information
Showing
6 changed files
with
101 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
nonunit-statement.scala:13: warning: expression in statement position is not assigned | ||
improved // warn | ||
^ | ||
nonunit-statement.scala:20: warning: expression in statement position is not assigned | ||
new E().toString // warn | ||
^ | ||
nonunit-statement.scala:26: warning: expression in statement position is not assigned | ||
Future(42) // warn | ||
^ | ||
nonunit-statement.scala:29: warning: expression in statement position is not assigned | ||
copy() // warn | ||
^ | ||
nonunit-statement.scala:36: warning: expression in statement position is not assigned | ||
27 +: xs // warn | ||
^ | ||
nonunit-statement.scala:39: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses | ||
null // warn for purity | ||
^ | ||
error: No warnings can be incurred under -Werror. | ||
6 warnings | ||
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
// scalac: -Werror -Wnonunit-statement | ||
|
||
package tpolecat | ||
|
||
import concurrent._ | ||
|
||
class C { | ||
import ExecutionContext.Implicits._ | ||
def c = { | ||
def improved = Future(42) | ||
def stale = Future(27) | ||
improved // warn | ||
stale | ||
} | ||
} | ||
class D { | ||
def d = { | ||
class E | ||
new E().toString // warn | ||
new E().toString * 2 | ||
} | ||
} | ||
class F { | ||
import ExecutionContext.Implicits._ | ||
Future(42) // warn | ||
} | ||
case class K(s: String) { | ||
copy() // warn | ||
} | ||
class Mutate { | ||
import collection.mutable._ | ||
val b = ListBuffer.empty[Int] | ||
b += 42 // nowarn | ||
val xs = List(42) | ||
27 +: xs // warn | ||
} | ||
class WhoCares { | ||
null // warn for purity | ||
??? // nowarn for impurity | ||
} | ||
class Absolution { | ||
def f(i: Int): Int = i+1 | ||
import ExecutionContext.Implicits._ | ||
Future(42): Unit // nowarn but attachment is not on implicit application | ||
f(42): Unit // nowarn | ||
} |