diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-05-02 13:21:06 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-05-02 16:18:35 +0200 |
commit | 49f50727944a478bc5d10ad0658437286f47e422 (patch) | |
tree | c4e7a931f24cccf3c371fca440ad94dd19efd371 /test/files/neg | |
parent | 5819b78c25c9cba25fc84018d3905fe265bb4e18 (diff) | |
parent | 98972c95ab1e7c0ea2af9c9a958c0de60eb26b3d (diff) | |
download | scala-49f50727944a478bc5d10ad0658437286f47e422.tar.gz scala-49f50727944a478bc5d10ad0658437286f47e422.tar.bz2 scala-49f50727944a478bc5d10ad0658437286f47e422.zip |
Merge 2.10.x into master
Conflicts:
bincompat-forward.whitelist.conf
src/compiler/scala/tools/nsc/matching/Patterns.scala
src/compiler/scala/tools/nsc/transform/patmat/Logic.scala
src/compiler/scala/tools/nsc/typechecker/Infer.scala
src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala
test/files/neg/t5663-badwarneq.check
Diffstat (limited to 'test/files/neg')
-rw-r--r-- | test/files/neg/delayed-init-ref.check | 12 | ||||
-rw-r--r-- | test/files/neg/delayed-init-ref.flags | 1 | ||||
-rw-r--r-- | test/files/neg/delayed-init-ref.scala | 42 | ||||
-rw-r--r-- | test/files/neg/t414.check | 2 | ||||
-rw-r--r-- | test/files/neg/t4879.check | 4 | ||||
-rw-r--r-- | test/files/neg/t5663-badwarneq.check | 34 | ||||
-rw-r--r-- | test/files/neg/t5663-badwarneq.scala | 18 | ||||
-rw-r--r-- | test/files/neg/t7330.check | 5 | ||||
-rw-r--r-- | test/files/neg/t7330.scala | 5 | ||||
-rw-r--r-- | test/files/neg/t7369.check | 15 | ||||
-rw-r--r-- | test/files/neg/t7369.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t7369.scala | 43 |
12 files changed, 171 insertions, 11 deletions
diff --git a/test/files/neg/delayed-init-ref.check b/test/files/neg/delayed-init-ref.check new file mode 100644 index 0000000000..ce5b205832 --- /dev/null +++ b/test/files/neg/delayed-init-ref.check @@ -0,0 +1,12 @@ +delayed-init-ref.scala:17: warning: Selecting value vall from object O, which extends scala.DelayedInit, is likely to yield an uninitialized value + println(O.vall) // warn + ^ +delayed-init-ref.scala:19: warning: Selecting value vall from object O, which extends scala.DelayedInit, is likely to yield an uninitialized value + println(vall) // warn + ^ +delayed-init-ref.scala:40: warning: Selecting value foo from trait UserContext, which extends scala.DelayedInit, is likely to yield an uninitialized value + println({locally(()); this}.foo) // warn (spurious, but we can't discriminate) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/test/files/neg/delayed-init-ref.flags b/test/files/neg/delayed-init-ref.flags new file mode 100644 index 0000000000..7949c2afa2 --- /dev/null +++ b/test/files/neg/delayed-init-ref.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/test/files/neg/delayed-init-ref.scala b/test/files/neg/delayed-init-ref.scala new file mode 100644 index 0000000000..f2aa804e28 --- /dev/null +++ b/test/files/neg/delayed-init-ref.scala @@ -0,0 +1,42 @@ +trait T { + val traitVal = "" +} + +object O extends App with T { + val vall = "" + lazy val lazyy = "" + def deff = "" + + println(vall) // no warn + new { + println(vall) // no warn + } +} + +object Client { + println(O.vall) // warn + import O.vall + println(vall) // warn + + println(O.lazyy) // no warn + println(O.deff) // no warn + println(O.traitVal) // no warn +} + +// Delayed init usage pattern from Specs2 +// See: https://groups.google.com/d/msg/scala-sips/wP6dL8nIAQs/ogjoPE-MSVAJ +trait Before extends DelayedInit { + def before() + override def delayedInit(x: => Unit): Unit = { before; x } +} +object Spec { + trait UserContext extends Before { + def before() = () + val foo = "foo" + } + new UserContext { + println(foo) // no warn + println(this.foo) // no warn + println({locally(()); this}.foo) // warn (spurious, but we can't discriminate) + } +} diff --git a/test/files/neg/t414.check b/test/files/neg/t414.check index e15dbaea71..30211eef8e 100644 --- a/test/files/neg/t414.check +++ b/test/files/neg/t414.check @@ -1,7 +1,7 @@ t414.scala:5: error: pattern type is incompatible with expected type; found : Empty.type required: IntMap[a] -Note: if you intended to match against the class, try `case _: Empty[_]` or `case Empty()` +Note: if you intended to match against the class, try `case Empty()` case Empty => ^ t414.scala:7: error: type mismatch; diff --git a/test/files/neg/t4879.check b/test/files/neg/t4879.check index 21cd329640..c7edd583c8 100644 --- a/test/files/neg/t4879.check +++ b/test/files/neg/t4879.check @@ -1,13 +1,13 @@ t4879.scala:6: error: pattern type is incompatible with expected type; found : C.type required: C -Note: if you intended to match against the class, try `case _: C` or `case C(_)` +Note: if you intended to match against the class, try `case C(_)` case C => true ^ t4879.scala:10: error: pattern type is incompatible with expected type; found : D.type required: D[T,U,V] -Note: if you intended to match against the class, try `case _: D[_,_,_]` or `case D(_,_,_)` +Note: if you intended to match against the class, try `case D(_,_,_)` case D => true ^ two errors found diff --git a/test/files/neg/t5663-badwarneq.check b/test/files/neg/t5663-badwarneq.check index 12e93ff373..732e4f44d0 100644 --- a/test/files/neg/t5663-badwarneq.check +++ b/test/files/neg/t5663-badwarneq.check @@ -1,24 +1,42 @@ -t5663-badwarneq.scala:42: warning: comparing case class values of types Some[Int] and None.type using `==' will always yield false +t5663-badwarneq.scala:47: warning: comparing case class values of types Some[Int] and None.type using `==' will always yield false println(new Some(1) == None) // Should complain on type, was: spuriously complains on fresh object ^ -t5663-badwarneq.scala:43: warning: comparing case class values of types Some[Int] and Thing using `==' will always yield false +t5663-badwarneq.scala:48: warning: comparing case class values of types Some[Int] and Thing using `==' will always yield false println(Some(1) == new Thing(1)) // Should complain on type, was: spuriously complains on fresh object ^ -t5663-badwarneq.scala:51: warning: ThingOne and Thingy are unrelated: they will most likely never compare equal +t5663-badwarneq.scala:56: warning: ThingOne and Thingy are unrelated: they will most likely never compare equal println(t1 == t2) // true, but apparently unrelated, a compromise warning ^ -t5663-badwarneq.scala:52: warning: ThingThree and Thingy are unrelated: they will most likely never compare equal +t5663-badwarneq.scala:57: warning: ThingThree and Thingy are unrelated: they will most likely never compare equal println(t4 == t2) // true, complains because ThingThree is final and Thingy not a subclass, stronger claim than unrelated ^ -t5663-badwarneq.scala:55: warning: comparing case class values of types ThingTwo and Some[Int] using `==' will always yield false +t5663-badwarneq.scala:60: warning: comparing case class values of types ThingTwo and Some[Int] using `==' will always yield false println(t3 == Some(1)) // false, warn on different cases ^ -t5663-badwarneq.scala:56: warning: comparing values of types ThingOne and Cousin using `==' will always yield false +t5663-badwarneq.scala:61: warning: comparing values of types ThingOne and Cousin using `==' will always yield false println(t1 == c) // should warn ^ -t5663-badwarneq.scala:64: warning: comparing case class values of types Simple and SimpleSibling.type using `==' will always yield false +t5663-badwarneq.scala:69: warning: comparing case class values of types Simple and SimpleSibling.type using `==' will always yield false println(new Simple() == SimpleSibling) // like Some(1) == None, but needn't be final case ^ +t5663-badwarneq.scala:72: warning: ValueClass1 and Int are unrelated: they will never compare equal + println(new ValueClass1(5) == 5) // bad + ^ +t5663-badwarneq.scala:74: warning: comparing values of types Int and ValueClass1 using `==' will always yield false + println(5 == new ValueClass1(5)) // bad + ^ +t5663-badwarneq.scala:78: warning: ValueClass2[String] and String are unrelated: they will never compare equal + println(new ValueClass2("abc") == "abc") // bad + ^ +t5663-badwarneq.scala:79: warning: ValueClass2[Int] and ValueClass1 are unrelated: they will never compare equal + println(new ValueClass2(5) == new ValueClass1(5)) // bad - different value classes + ^ +t5663-badwarneq.scala:81: warning: comparing values of types ValueClass3 and ValueClass2[Int] using `==' will always yield false + println(ValueClass3(5) == new ValueClass2(5)) // bad + ^ +t5663-badwarneq.scala:82: warning: comparing values of types ValueClass3 and Int using `==' will always yield false + println(ValueClass3(5) == 5) // bad + ^ error: No warnings can be incurred under -Xfatal-warnings. -7 warnings found +13 warnings found one error found diff --git a/test/files/neg/t5663-badwarneq.scala b/test/files/neg/t5663-badwarneq.scala index 56ec389c03..3c0376914e 100644 --- a/test/files/neg/t5663-badwarneq.scala +++ b/test/files/neg/t5663-badwarneq.scala @@ -17,6 +17,11 @@ class SimpleParent case class Simple() extends SimpleParent case object SimpleSibling extends SimpleParent +// value classes +final class ValueClass1(val value: Int) extends AnyVal +final class ValueClass2[T](val value: T) extends AnyVal +final case class ValueClass3(val value: Int) extends AnyVal + /* It's not possible to run partest without -deprecation. * Since detecting the warnings requires a neg test with * -Xfatal-warnings, and deprecation terminates the compile, @@ -63,6 +68,19 @@ object Test { println(new Simple() == SimpleSibling) // like Some(1) == None, but needn't be final case + println(new ValueClass1(5) == new ValueClass1(5)) // ok + println(new ValueClass1(5) == 5) // bad + println(new ValueClass1(5) == (5: Any)) // ok, have to let it through + println(5 == new ValueClass1(5)) // bad + println((5: Any) == new ValueClass1(5) == (5: Any)) // ok + + println(new ValueClass2("abc") == new ValueClass2("abc")) // ok + println(new ValueClass2("abc") == "abc") // bad + println(new ValueClass2(5) == new ValueClass1(5)) // bad - different value classes + println(ValueClass3(5) == new ValueClass3(5)) // ok + println(ValueClass3(5) == new ValueClass2(5)) // bad + println(ValueClass3(5) == 5) // bad + /* val mine = new MyThing val some = new SomeThing diff --git a/test/files/neg/t7330.check b/test/files/neg/t7330.check new file mode 100644 index 0000000000..b96d656d2b --- /dev/null +++ b/test/files/neg/t7330.check @@ -0,0 +1,5 @@ +t7330.scala:4: error: pattern must be a value: Y[_] +Note: if you intended to match against the class, try `case _: Y[_]` + 0 match { case Y[_] => } + ^ +one error found diff --git a/test/files/neg/t7330.scala b/test/files/neg/t7330.scala new file mode 100644 index 0000000000..13a943a02b --- /dev/null +++ b/test/files/neg/t7330.scala @@ -0,0 +1,5 @@ +class Y[T] +class Test { + // TypeTree is not a valid tree for a pattern + 0 match { case Y[_] => } +}
\ No newline at end of file diff --git a/test/files/neg/t7369.check b/test/files/neg/t7369.check new file mode 100644 index 0000000000..a4e99f496e --- /dev/null +++ b/test/files/neg/t7369.check @@ -0,0 +1,15 @@ +t7369.scala:6: warning: unreachable code + case Tuple1(X) => // unreachable + ^ +t7369.scala:13: warning: unreachable code + case Tuple1(true) => // unreachable + ^ +t7369.scala:31: warning: unreachable code + case Tuple1(X) => // unreachable + ^ +t7369.scala:40: warning: unreachable code + case Tuple1(null) => // unreachable + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/test/files/neg/t7369.flags b/test/files/neg/t7369.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/neg/t7369.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t7369.scala b/test/files/neg/t7369.scala new file mode 100644 index 0000000000..87ddfe98b7 --- /dev/null +++ b/test/files/neg/t7369.scala @@ -0,0 +1,43 @@ +object Test { + val X, Y = true + (null: Tuple1[Boolean]) match { + case Tuple1(X) => + case Tuple1(Y) => + case Tuple1(X) => // unreachable + case _ => + } + + (null: Tuple1[Boolean]) match { + case Tuple1(true) => + case Tuple1(false) => + case Tuple1(true) => // unreachable + case _ => + } +} + + +sealed abstract class B; +case object True extends B; +case object False extends B; + +object Test2 { + + val X: B = True + val Y: B = False + + (null: Tuple1[B]) match { + case Tuple1(X) => + case Tuple1(Y) => + case Tuple1(X) => // unreachable + case _ => + } +} + +object Test3 { + (null: Tuple1[B]) match { + case Tuple1(null) => + case Tuple1(True) => + case Tuple1(null) => // unreachable + case _ => + } +} |