aboutsummaryrefslogtreecommitdiff
path: root/tests/pending/run/patmat_unapp_abstype-new.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2015-05-12 18:30:53 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-05-12 18:30:53 +0200
commit89bacb9c25a58454ff1878e67f7ea07ffc8c269f (patch)
tree51f1ff6c66aebe1b6109b1cffcc2bb8e4cf760a3 /tests/pending/run/patmat_unapp_abstype-new.scala
parenta0fa33deafbea1bf53edc068c5ed9db5592822f9 (diff)
downloaddotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.tar.gz
dotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.tar.bz2
dotty-89bacb9c25a58454ff1878e67f7ea07ffc8c269f.zip
Run tests as they were in scala.
Diffstat (limited to 'tests/pending/run/patmat_unapp_abstype-new.scala')
-rw-r--r--tests/pending/run/patmat_unapp_abstype-new.scala76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/pending/run/patmat_unapp_abstype-new.scala b/tests/pending/run/patmat_unapp_abstype-new.scala
new file mode 100644
index 000000000..c2927bd12
--- /dev/null
+++ b/tests/pending/run/patmat_unapp_abstype-new.scala
@@ -0,0 +1,76 @@
+import reflect.{ClassTag, classTag}
+
+// abstract types and extractors, oh my!
+trait TypesAPI {
+ trait Type
+
+ type TypeRef <: Type
+ val TypeRef: TypeRefExtractor; trait TypeRefExtractor {
+ def apply(x: Int): TypeRef
+ def unapply(x: TypeRef): Option[(Int)]
+ }
+
+ // just for illustration, should follow the same pattern as TypeRef
+ case class MethodType(n: Int) extends Type
+}
+
+// user should not be exposed to the implementation
+trait TypesUser extends TypesAPI {
+ def shouldNotCrash(tp: Type): Unit = {
+ tp match {
+ case TypeRef(x) => println("TypeRef")
+ case MethodType(x) => println("MethodType")
+ case _ => println("none of the above")
+ }
+ }
+}
+
+trait TypesImpl extends TypesAPI {
+ object TypeRef extends TypeRefExtractor // this will have a bridged unapply(x: Type) = unapply(x.asInstanceOf[TypeRef])
+ case class TypeRef(n: Int) extends Type // this has a bridge from TypesAPI#Type to TypesImpl#TypeRef
+ // --> the cast in the bridge will fail because the pattern matcher can't type test against the abstract types in TypesUser
+}
+
+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)) // prints "TypeRef"
+ shouldNotCrash(MethodType(10)) // prints "MethodType"
+ }
+}
+
+object TestUnappDynamicSynth extends RealFoos with Intermed {
+ case class NotAFoo(n: Int) extends Bar
+ def test() = {
+ crash(NotAFoo(10))
+ crash(new Foo(5))
+ }
+}
+
+object Test extends App {
+ TestUnappStaticallyKnownSynthetic.test()
+ TestUnappDynamicSynth.test()
+}