diff options
author | Paul Phillips <paulp@improving.org> | 2012-10-12 22:24:32 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-10-13 07:28:30 -0700 |
commit | 02909f2be30db5c0f79f961cad17e2dc2f026ff4 (patch) | |
tree | 7a47e916ec196d4c8e34832eebacc21b76c4b997 /test | |
parent | 8a984fa0e351de532497450c9c80ddd2f975d32e (diff) | |
download | scala-02909f2be30db5c0f79f961cad17e2dc2f026ff4.tar.gz scala-02909f2be30db5c0f79f961cad17e2dc2f026ff4.tar.bz2 scala-02909f2be30db5c0f79f961cad17e2dc2f026ff4.zip |
Warn about more misplaced expressions.
An identifier being used in statement position is not likely
what was meant when it is a non-lazy getter.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/unit-returns-value.check | 8 | ||||
-rw-r--r-- | test/files/neg/unit-returns-value.scala | 23 |
2 files changed, 29 insertions, 2 deletions
diff --git a/test/files/neg/unit-returns-value.check b/test/files/neg/unit-returns-value.check index 363946f94d..f30a506ebe 100644 --- a/test/files/neg/unit-returns-value.check +++ b/test/files/neg/unit-returns-value.check @@ -4,6 +4,12 @@ unit-returns-value.scala:4: warning: a pure expression does nothing in statement unit-returns-value.scala:4: warning: enclosing method f has result type Unit: return value discarded if (b) return 5 ^ +unit-returns-value.scala:22: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + i1 // warn + ^ +unit-returns-value.scala:23: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + i2 // warn + ^ error: No warnings can be incurred under -Xfatal-warnings. -two warnings found +four warnings found one error found diff --git a/test/files/neg/unit-returns-value.scala b/test/files/neg/unit-returns-value.scala index ecc981f217..fc5a37069f 100644 --- a/test/files/neg/unit-returns-value.scala +++ b/test/files/neg/unit-returns-value.scala @@ -3,9 +3,30 @@ object Test { var b = false if (b) return 5 } - + // no warning def g { return println("hello") } } + +class UnusedValues { + var i1 = 2 + val i2 = 2 + lazy val i3 = 2 + object i4 { } + def i5 = 2 + final def i6 = 2 + + def x = { + i1 // warn + i2 // warn + i3 // no warn + i4 // no warn + i5 // no warn + i6 // could warn someday, if i6 returned 2.type instead of Int + + 5 + } +} + |