summaryrefslogtreecommitdiff
path: root/test/files/scalacheck
diff options
context:
space:
mode:
authorDenys Shabalin <denys.shabalin@typesafe.com>2014-03-22 13:14:37 +0100
committerEugene Burmako <xeno.by@gmail.com>2014-03-25 20:16:52 +0100
commit0bac64d64309e2f236ba25d8e57b1ea1f62d4d8c (patch)
treece121f4a26af1a6ea84248770b4bf7b92a7a58cc /test/files/scalacheck
parentc765537cb3532a7b88f1b68331840953f3e9d048 (diff)
downloadscala-0bac64d64309e2f236ba25d8e57b1ea1f62d4d8c.tar.gz
scala-0bac64d64309e2f236ba25d8e57b1ea1f62d4d8c.tar.bz2
scala-0bac64d64309e2f236ba25d8e57b1ea1f62d4d8c.zip
SI-8388 consistently match type trees by originals
Due to the fact that all TypTrees are transformed into TypeTrees during typechecking one couldn't treat typed type trees in the same way as they treat untyped type trees. This change implements support for pattern matching of TypeTrees as their corresponding TypTree equivalent using tree preserved in the original. The implementation itself is a trivial wrapping of regular TypTree extractors into MaybeTypeTreeOriginal.
Diffstat (limited to 'test/files/scalacheck')
-rw-r--r--test/files/scalacheck/quasiquotes/TypecheckedProps.scala96
1 files changed, 76 insertions, 20 deletions
diff --git a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala
index fb2eb69321..a5d526191f 100644
--- a/test/files/scalacheck/quasiquotes/TypecheckedProps.scala
+++ b/test/files/scalacheck/quasiquotes/TypecheckedProps.scala
@@ -2,32 +2,13 @@ import org.scalacheck._, Prop._, Gen._, Arbitrary._
import scala.reflect.runtime.universe._, Flag._, internal.reificationSupport._
object TypecheckedProps extends QuasiquoteProperties("typechecked") {
- def original(tree: Tree) = tree match {
- case tt: TypeTree => Some(tt.original)
- case _ => None
- }
- def originals(trees: List[Tree]) = trees.flatMap(original)
- val int = ScalaDot(TypeName("Int"))
- val intint = List(int, int)
+
property("tuple term") = test {
val q"(..$elements)" = typecheck(q"(1, 2)")
assert(elements ≈ List(q"1", q"2"))
}
- property("tuple type") = test {
- val tq"(..$els0)" = typecheckTyp(tq"Unit")
- assert(els0.isEmpty)
- val tq"(..$els1)" = typecheckTyp(tq"(Int, Int)")
- assert(originals(els1) ≈ intint)
- }
-
- property("function type") = test {
- val tq"(..$argtpes) => $restpe" = typecheckTyp(tq"(Int, Int) => Int")
- assert(originals(argtpes) ≈ intint)
- assert(original(restpe).get ≈ int)
- }
-
property("for/for-yield") = test {
val enums = fq"x <- xs" :: fq"x1 = x + 1" :: fq"if x1 % 2 == 0" :: Nil
val body = q"x1"
@@ -158,3 +139,78 @@ object TypecheckedProps extends QuasiquoteProperties("typechecked") {
assert(cases ≈ q"{ case 1 => () }".cases)
}
}
+
+trait TypecheckedTypes { self: QuasiquoteProperties =>
+ property("type ident") = test {
+ val q"$_; type $_ = $tpt" = typecheck(q"class C; type T = C")
+ val tq"C" = tpt
+ }
+
+ property("type select") = test {
+ val tq"scala.Int" = typecheckTyp(tq"Int")
+ }
+
+ property("this type select") = test {
+ val q"class $_ { $_; type $_ = $tpt }" = typecheck(q"class C { type A = Int; type B = this.A }")
+ val tq"this.$name" = tpt
+ val TypeName("A") = name
+ }
+
+ property("super type select") = test {
+ val q"$_; class $_ extends $_ { type $_ = $tpt }" =
+ typecheck(q"class C1 { type A = Int }; class C2 extends C1 { type B = super[C1].A }")
+ val tq"$empty.super[$c1].$a" = tpt
+ val TypeName("") = empty
+ val TypeName("C1") = c1
+ val TypeName("A") = a
+ }
+
+ property("applied type") = test {
+ val tt = typecheckTyp(q"Map[Int, Int]")
+ val tq"$tpt[..$tpts]" = tt
+ val tq"scala.this.Predef.Map" = tpt
+ val List(tq"scala.Int", tq"scala.Int") = tpts
+ }
+
+ property("tuple type") = test {
+ val tq"(..$els0)" = typecheckTyp(tq"Unit")
+ assert(els0.isEmpty)
+ val tq"(..$els1)" = typecheckTyp(tq"(Int, Int)")
+ val List(tq"scala.Int", tq"scala.Int") = els1
+ }
+
+ property("function type") = test {
+ val tq"(..$argtpes) => $restpe" = typecheckTyp(tq"(Int, Int) => Int")
+ val List(tq"scala.Int", tq"scala.Int") = argtpes
+ val tq"scala.Int" = restpe
+ }
+
+ property("compound type") = test {
+ val tq"..$parents { ..$defns }" = typecheckTyp(tq"Int { def x: Int }")
+ val List(tq"Int") = parents
+ val List(q"def x: Int") = defns
+ }
+
+ property("singleton type") = test {
+ val tq"$ref.type" = typecheckTyp(tq"scala.Predef.type")
+ val q"scala.Predef" = ref
+ }
+
+ property("type projection") = test {
+ val tq"$tpt#$name" = typecheckTyp(tq"({ type T = Int })#T")
+ val TypeName("T") = name
+ val tq"{ type T = Int }" = tpt
+ }
+
+ property("annotated type") = test {
+ val tq"$tpt @$annot" = typecheckTyp(tq"Int @unchecked")
+ val tq"scala.Int" = tpt
+ val q"new unchecked" = annot
+ }
+
+ property("existential type") = test {
+ val tq"$tpt forSome { ..$defns }" = typecheckTyp(tq"T forSome { type T }")
+ val tq"T" = tpt
+ val q"type T" :: Nil = defns
+ }
+}