diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-25 18:11:29 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-25 18:21:33 -0700 |
commit | 9d423c9bb76dddcd080d98f4a05c02856708fc06 (patch) | |
tree | 764110f7277097e6acdc6efe5ce44040decd5fcc /test/files/run | |
parent | 5499e41157cdb6a81772728525e9c1f44401e7cc (diff) | |
download | scala-9d423c9bb76dddcd080d98f4a05c02856708fc06.tar.gz scala-9d423c9bb76dddcd080d98f4a05c02856708fc06.tar.bz2 scala-9d423c9bb76dddcd080d98f4a05c02856708fc06.zip |
Improvements to unchecked warnings.
Closes SI-6275, SI-5762.
The comment says is better than I can.
/** On pattern matcher checkability:
*
* Consider a pattern match of this form: (x: X) match { case _: P => }
*
* There are four possibilities to consider:
* [P1] X will always conform to P
* [P2] x will never conform to P
* [P3] X <: P if some runtime test is true
* [P4] X cannot be checked against P
*
* The first two cases correspond to those when there is enough static
* information to say X <: P or that !(X <: P) for all X and P.
* The fourth case includes unknown abstract types or structural
* refinements appearing within a pattern.
*
* The third case is the interesting one. We designate another type, XR,
* which is essentially the intersection of X and |P|, where |P| is
* the erasure of P. If XR <: P, then no warning is emitted.
*
* Examples of how this info is put to use:
* sealed trait A[T] ; class B[T] extends A[T]
* def f(x: B[Int]) = x match { case _: A[Int] if true => }
* def g(x: A[Int]) = x match { case _: B[Int] => }
*
* `f` requires no warning because X=B[Int], P=A[Int], and B[Int] <:< A[Int].
* `g` requires no warning because X=A[Int], P=B[Int], XR=B[Int], and B[Int] <:< B[Int].
* XR=B[Int] because a value of type A[Int] which is tested to be a B can
* only be a B[Int], due to the definition of B (B[T] extends A[T].)
*
* This is something like asSeenFrom, only rather than asking what a type looks
* like from the point of view of one of its base classes, we ask what it looks
* like from the point of view of one of its subclasses.
*/
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/t576.scala | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/test/files/run/t576.scala b/test/files/run/t576.scala index dc09d8dc98..756a241572 100644 --- a/test/files/run/t576.scala +++ b/test/files/run/t576.scala @@ -12,7 +12,7 @@ object Dingus { object Test { val x1 = new A val x2 = new A - + val x3 = new { self => override def equals(other : Any) = other match { case that: self.type => true @@ -20,7 +20,7 @@ object Test { } } val x4 = new { self => - def f(x: Any) = x match { + def f(x: Any): Int = x match { case _: x1.type => 1 case _: x2.type => 2 case _: x3.type => 3 @@ -35,11 +35,11 @@ object Test { assert(x1 != x2) assert(x1 != ()) assert(x2 != x1) - + assert(x3 == x3) assert(x3 != x2) assert(x2 != x3) - + List(x1, x2, x3, x4, Dingus) map x4.f foreach println } -}
\ No newline at end of file +} |