summaryrefslogtreecommitdiff
path: root/test/files/neg/checksensible.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-08-10 04:03:07 +0000
committerPaul Phillips <paulp@improving.org>2010-08-10 04:03:07 +0000
commitca0bb2c4191ff9cd7b1c5f0f8315a4db65785519 (patch)
treee7829e8bc96f6459257b092507497c1cba10794b /test/files/neg/checksensible.scala
parent024c0220d1d11afef2c8271f3620eaebadcebefa (diff)
downloadscala-ca0bb2c4191ff9cd7b1c5f0f8315a4db65785519.tar.gz
scala-ca0bb2c4191ff9cd7b1c5f0f8315a4db65785519.tar.bz2
scala-ca0bb2c4191ff9cd7b1c5f0f8315a4db65785519.zip
An overhaul of checkSensible.
gives fewer insensible warnings about actually sensible things, etc. Large test case with 30 warnings elicited. Closes #282 (again), no review.
Diffstat (limited to 'test/files/neg/checksensible.scala')
-rw-r--r--test/files/neg/checksensible.scala96
1 files changed, 73 insertions, 23 deletions
diff --git a/test/files/neg/checksensible.scala b/test/files/neg/checksensible.scala
index 092c08592f..f67e9ea57f 100644
--- a/test/files/neg/checksensible.scala
+++ b/test/files/neg/checksensible.scala
@@ -1,38 +1,88 @@
-class Test {
+final class Bip { def <=(other: Bop) = true }
+final class Bop { }
+object Bep { }
+
+final class Zing {
+ def !=(other: Zing) = false
+}
+
+// 7 warnings
+class RefEqTest {
+ object Shmoopie
+
+ (new AnyRef) eq (new AnyRef)
+ (new AnyRef) ne (new AnyRef)
+ Shmoopie eq (new AnyRef)
+ (Shmoopie: AnyRef) eq (new AnyRef)
+ (new AnyRef) eq Shmoopie
+ (new AnyRef) eq null
+ null eq new AnyRef
+}
+
+// 11 warnings
+class EqEqValTest {
var c = 0
- println((c = 1) == 0)
- println(1 == "abc")
- println(1 != true)
+ (c = 1) == 0
+ 0 == (c = 1)
+
+ 1 == "abc"
+ "abc" == 1 // doesn't warn since String defines an equals method
+
+ new AnyRef == 1
+ 1 == new AnyRef
+
+ 1 != true
+ () == true
+ () == ()
+ () == println
+
+ (1 != println)
+ (1 != 'sym)
+}
- println(((x: Int) => x + 1) == null)
- println(new Object == new Object)
- println(new Exception() != new Exception())
+// 12 warnings
+class EqEqRefTest {
+ val ref = new Bop
+ ((x: Int) => x + 1) == null
+ Bep == ((_: Int) + 1)
+
+ new Object == new Object
+ new Object == "abc"
+ new Exception() != new Exception()
val foo: Array[String] = Array("1","2","3")
- if (foo.length == null) // == 0 makes more sense, but still
- println("plante") // this code leads to runtime crash
- else
- println("plante pas")
+ if (foo.length == null) "plante" else "plante pas"
+
+ // final classes with default equals
+ val x1 = new Bip
+ val x2 = new Bop
+ (x1 == x2)
+
+ class C1 { }
+ class C2 extends C1 { }
+ final class Z1 extends C2 { }
+ final class C3 extends C2 { def !=(other: Z1) = false }
+ val z1 = new Z1
+ val c3 = new C3
+
+ // all but c3 != z1 should warn
+ c3 != z1
+ c3 == z1
+ z1 == c3
+ z1 != c3
+ c3 != "abc"
+
+ // non-warners
+ (null: AnyRef) == (null: AnyRef)
+ (x1 <= x2)
def main(args: Array[String]) = {
val in = new java.io.FileInputStream(args(0))
-
var c = 0
while ((c = in.read) != -1)
print(c.toChar)
in.close
}
-
- println({} == true)
- println("hello" == 2)
- println(new Object == 1)
- println(1 == (new Object))
-
- def isabstract: Int
-
- println(1 != println)
- println(1 != 'sym)
-
}