diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-28 06:55:49 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-28 07:19:01 -0700 |
commit | 886c4061222773d76f3ee3f4ff1469f9d4a48eaf (patch) | |
tree | 70b13842e325bafd48e5494c844078f35b02f5b7 /test/files/neg/unchecked3.scala | |
parent | 41f37bc428a309b9766f545da0179f270ea01d77 (diff) | |
parent | 57db28c55c3610f508b07940f7077cb73932418f (diff) | |
download | scala-886c4061222773d76f3ee3f4ff1469f9d4a48eaf.tar.gz scala-886c4061222773d76f3ee3f4ff1469f9d4a48eaf.tar.bz2 scala-886c4061222773d76f3ee3f4ff1469f9d4a48eaf.zip |
Merge branch '2.10.x' into 210-merge
* 2.10.x: (37 commits)
Added logic and tests for unchecked refinements.
Moved isNonRefinementClassType somewhere logical.
Moved two tests to less breaky locations.
Nailed down the "impossible match" logic.
Finish docs for string interpolation.
moves Context.ParseError outside the cake
revives macros.Infrastructure
moves Context.runtimeUniverse to TreeBuild.mkRuntimeUniverseRef
a more precise type for Context.mirror
gets rid of macros.Infrastructure
simplifies Context.Run and Context.CompilationUnit
exposes Position.source as SourceFile
removes extraneous stuff from macros.Infrastructure
merges macros.CapturedVariables into macros.Universe
merges macros.Exprs and macros.TypeTags into Context
removes front ends from scala-reflect.jar
PositionApi => Position
hides BuildUtils from Scaladoc
MirrorOf => Mirror
docs.pre-lib now checks for mods in reflect
...
Conflicts:
test/files/neg/t4302.check
test/files/neg/unchecked.check
test/files/neg/unchecked2.check
Diffstat (limited to 'test/files/neg/unchecked3.scala')
-rw-r--r-- | test/files/neg/unchecked3.scala | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/files/neg/unchecked3.scala b/test/files/neg/unchecked3.scala new file mode 100644 index 0000000000..7b8c13e8f8 --- /dev/null +++ b/test/files/neg/unchecked3.scala @@ -0,0 +1,83 @@ +sealed trait A2[T1] +final class B2[T1, T2] extends A2[T1] + +sealed trait A[T] +final class B[T] extends A[T] + +sealed trait A1[T] +trait B1[T] extends A1[T] +trait C1[T] extends A1[T] +trait D1[T] extends A1[Int] +trait E1[T] extends B1[Int] +trait F1[T] extends B1[T] + +object MiscUnchecked { + /* nowarn */ def knownType1(x: A[Int]) = x match { case _: B[Int] if true => 1 } + /* nowarn */ def knownType2(x: B[Int]) = x match { case _: A[Int] if true => 1 } + /* nowarn */ def tparamLeakage1(x: Any) = x match { case Array() => 1 } + /* nowarn */ def tparamLeakage2(x: Any) = x match { case List() => 1 } + + // E1[Double] implies B1[Int], but B1[Int] does not imply E1[Double], even if .isInstanceOf[E1[_]] + // F1[Int] implies B1[Int], and B1[Int] implies F1[Int] + + /* nowarn */ def peerTypes1(x: B1[Int]) = x match { case _: C1[Int] => true } + /* warn */ def peerTypes2(x: B1[Int]) = x match { case _: E1[Double] => true } + /* warn */ def peerTypes3(x: B1[_]) = x match { case _: F1[Double] => true } + /* nowarn */ def peerTypes4(x: B1[Int]) = x match { case _: F1[Int] => true } + + /* warn */ def twotypes1[T](x: B2[T, Int]) = x match { case _: A2[Int] => true } + /* nowarn */ def twotypes2[T](x: B2[Int, T]) = x match { case _: A2[Int] => true } + /* nowarn */ def twotypes3(x: A2[Int]) = x match { case _: B2[Int, _] => true } + /* nowarn */ def twotypes4[T](x: A2[T]) = x match { case _: B2[T, _] => true } + /* warn */ def twotypes5[T](x: A2[T]) = x match { case _: B2[_, Int] => true } +} + +object Arrays { + def f1(x: Any) = x match { + /* nowarn */ case _: Array[Int] => () + /* nowarn */ case _: Array[Boolean] => () + /* nowarn */ case _: Array[String] => () + /* warn */ case _: Array[List[String]] => () + /* nowarn */ case _: Array[Array[String]] => () + /* nowarn */ case _: Array[Array[Array[String]]] => () + /* warn */ case _: Array[Array[List[String]]] => () + } + + def f2(x: Array[_]) = x match { + /* nowarn */ case _: Array[Int] => () + /* nowarn */ case _: Array[Boolean] => () + /* nowarn */ case _: Array[String] => () + /* warn */ case _: Array[List[String]] => () + /* nowarn */ case _: Array[Array[String]] => () + /* nowarn */ case _: Array[Array[Array[String]]] => () + /* warn */ case _: Array[Array[List[String]]] => () + } + + def f3[T](x: Array[T]) = x match { + /* nowarn */ case _: Array[Int] => () + /* nowarn */ case _: Array[Boolean] => () + /* nowarn */ case _: Array[String] => () + /* warn */ case _: Array[List[String]] => () + /* nowarn */ case _: Array[Array[String]] => () + /* warn */ case _: Array[List[Array[String]]] => () + /* warn */ case _: Array[Array[List[String]]] => () + } +} + +object Matching { + class Q { + type A + type B <: A + + def f(xs: Traversable[B]) = xs match { + /* nowarn */ case xs: List[A] => xs.head + /* nowarn */ case xs: Seq[B] => xs.head + /* warn */ case xs: Set[A] => xs.head + } + def f2[T <: B](xs: Traversable[T]) = xs match { + /* nowarn */ case xs: List[B with T] => xs.head + /* nowarn */ case xs: Seq[A] => xs.head + /* nowarn */ case xs: Set[T] => xs.head + } + } +} |