summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-04-13 18:52:12 +0200
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-04-14 11:50:27 +0200
commit3515ac4449c72992be411e1e0579d76189dc7bf1 (patch)
treedac0bcf20a2fd49d6cacefbb9c7014b02a2f6a56 /test/files
parentd383f458aa5c53629727c5b6abb5134218471543 (diff)
downloadscala-3515ac4449c72992be411e1e0579d76189dc7bf1.tar.gz
scala-3515ac4449c72992be411e1e0579d76189dc7bf1.tar.bz2
scala-3515ac4449c72992be411e1e0579d76189dc7bf1.zip
more prudent bridging to unapply[Seq]
since we can't statically know whether the unapply we'll be bridging to is synthetic, drop this condition, and do pessimistic bridging for all unapply[Seq] (i.e., if we can't statically guarantee the type that would be assumed to be safe to cast to by a synthetic extractor, do the type test and return None if it fails)
Diffstat (limited to 'test/files')
-rw-r--r--test/files/run/patmat_unapp_abstype.check2
-rw-r--r--test/files/run/patmat_unapp_abstype.scala49
2 files changed, 46 insertions, 5 deletions
diff --git a/test/files/run/patmat_unapp_abstype.check b/test/files/run/patmat_unapp_abstype.check
index ac28ccdb95..72239d16cd 100644
--- a/test/files/run/patmat_unapp_abstype.check
+++ b/test/files/run/patmat_unapp_abstype.check
@@ -1,2 +1,4 @@
TypeRef
none of the above
+Bar
+Foo
diff --git a/test/files/run/patmat_unapp_abstype.scala b/test/files/run/patmat_unapp_abstype.scala
index e5adec5c16..fb0b491d39 100644
--- a/test/files/run/patmat_unapp_abstype.scala
+++ b/test/files/run/patmat_unapp_abstype.scala
@@ -32,8 +32,47 @@ trait TypesImpl extends TypesAPI {
//lazy val typeRefMani = manifest[TypeRef]
}
-object Test extends TypesImpl with TypesUser with App {
- shouldNotCrash(TypeRef(10)) // should and does print "TypeRef"
- // once #1697/#2337 are fixed, this should generate the correct output
- shouldNotCrash(MethodType(10)) // should print "MethodType" but prints "none of the above" -- good one, pattern matcher!
-} \ No newline at end of file
+trait Foos {
+ trait Bar
+ type Foo <: Bar
+ trait FooExtractor {
+ def unapply(foo: Foo): Option[Int]
+ }
+ val Foo: FooExtractor
+}
+
+trait RealFoos extends Foos {
+ class Foo(val x: Int) extends Bar
+ object Foo extends FooExtractor {
+ def unapply(foo: Foo): Option[Int] = Some(foo.x)
+ }
+}
+
+trait Intermed extends Foos {
+ def crash(bar: Bar): Unit =
+ bar match {
+ case Foo(x) => println("Foo")
+ case _ => println("Bar")
+ }
+}
+
+object TestUnappStaticallyKnownSynthetic extends TypesImpl with TypesUser {
+ def test() = {
+ shouldNotCrash(TypeRef(10)) // should and does print "TypeRef"
+ // once #1697/#2337 are fixed, this should generate the correct output
+ shouldNotCrash(MethodType(10)) // should print "MethodType" but prints "none of the above" -- good one, pattern matcher!
+ }
+}
+
+object TestUnappDynamicSynth extends RealFoos with Intermed {
+ case class FooToo(n: Int) extends Bar
+ def test() = {
+ crash(FooToo(10))
+ crash(new Foo(5))
+ }
+}
+
+object Test extends App {
+ TestUnappStaticallyKnownSynthetic.test()
+ TestUnappDynamicSynth.test()
+}