From ca0bb2c4191ff9cd7b1c5f0f8315a4db65785519 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 10 Aug 2010 04:03:07 +0000 Subject: 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. --- test/files/neg/checksensible.scala | 96 +++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 23 deletions(-) (limited to 'test/files/neg/checksensible.scala') 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) - } -- cgit v1.2.3