summaryrefslogtreecommitdiff
path: root/test/files/run/manifests.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-04-12 01:59:46 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-04-12 02:04:14 +0200
commit814cf34fb00f9ccb001249f4b3445ebc4f9942c9 (patch)
tree24dd54da571d27f10b0c482a6e08932c318fd7b2 /test/files/run/manifests.scala
parentdb3056f11730da19e4e56f09f12e300bda62f57c (diff)
downloadscala-814cf34fb00f9ccb001249f4b3445ebc4f9942c9.tar.gz
scala-814cf34fb00f9ccb001249f4b3445ebc4f9942c9.tar.bz2
scala-814cf34fb00f9ccb001249f4b3445ebc4f9942c9.zip
Next generation of macros
Implements SIP 16: Self-cleaning macros: http://bit.ly/wjjXTZ Features: * Macro defs * Reification * Type tags * Manifests aliased to type tags * Extended reflection API * Several hundred tests * 1111 changed files Not yet implemented: * Reification of refined types * Expr.value splicing * Named and default macro expansions * Intricacies of interaction between macros and implicits * Emission of debug information for macros (compliant with JSR-45) Dedicated to Yuri Alekseyevich Gagarin
Diffstat (limited to 'test/files/run/manifests.scala')
-rw-r--r--test/files/run/manifests.scala71
1 files changed, 32 insertions, 39 deletions
diff --git a/test/files/run/manifests.scala b/test/files/run/manifests.scala
index 6b6ea80b34..2d64bf18a9 100644
--- a/test/files/run/manifests.scala
+++ b/test/files/run/manifests.scala
@@ -4,29 +4,29 @@ object Test
val CO, IN, CONTRA = Value
}
import Variances.{ CO, IN, CONTRA }
-
+
object SubtypeRelationship extends Enumeration {
val NONE, SAME, SUB, SUPER = Value
}
import SubtypeRelationship.{ NONE, SAME, SUB, SUPER }
-
+
class VarianceTester[T, U, CC[_]](expected: Variances.Value)(
implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) {
-
- def elements = List(ev1 <:< ev2, ev2 <:< ev1)
- def containers = List(ev3 <:< ev4, ev4 <:< ev3)
+
+ def elements = List(ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe)
+ def containers = List(ev3.tpe <:< ev4.tpe, ev4.tpe <:< ev3.tpe)
def isUnrelated = typeCompare[T, U] == NONE
def isSame = typeCompare[T, U] == SAME
def isSub = typeCompare[T, U] == SUB
def isSuper = typeCompare[T, U] == SUPER
-
+
def showsCovariance = (elements == containers)
def showsContravariance = (elements == containers.reverse)
def showsInvariance = containers forall (_ == isSame)
def allContainerVariances = List(showsCovariance, showsInvariance, showsContravariance)
-
+
def showsExpectedVariance =
if (isUnrelated) allContainerVariances forall (_ == false)
else if (isSame) allContainerVariances forall (_ == true)
@@ -36,64 +36,57 @@ object Test
case CONTRA => showsContravariance && !showsCovariance && !showsInvariance
}
}
-
+
def showsCovariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) =
new VarianceTester[T, U, CC](CO) showsExpectedVariance
def showsInvariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) =
new VarianceTester[T, U, CC](IN) showsExpectedVariance
-
+
def showsContravariance[T, U, CC[_]](implicit ev1: Manifest[T], ev2: Manifest[U], ev3: Manifest[CC[T]], ev4: Manifest[CC[U]]) =
new VarianceTester[T, U, CC](CONTRA) showsExpectedVariance
-
- def typeCompare[T, U](implicit ev1: Manifest[T], ev2: Manifest[U]) = {
- // checking types as well
- if ((ev1 <:< ev2) != (ev1.tpe <:< ev2.tpe))
- println("Failed! " + ((ev1, ev2)))
-
- if ((ev2 <:< ev1) != (ev2.tpe <:< ev1.tpe))
- println("Failed! " + ((ev2, ev1)))
- (ev1 <:< ev2, ev2 <:< ev1) match {
+ def typeCompare[T, U](implicit ev1: Manifest[T], ev2: Manifest[U]) = {
+ (ev1.tpe <:< ev2.tpe, ev2.tpe <:< ev1.tpe) match {
case (true, true) => SAME
case (true, false) => SUB
case (false, true) => SUPER
case (false, false) => NONE
}
}
-
+
def assertAnyRef[T: Manifest] = List(
- manifest[T] <:< manifest[Any],
- manifest[T] <:< manifest[AnyRef],
- !(manifest[T] <:< manifest[AnyVal])
+ manifest[T].tpe <:< manifest[Any].tpe,
+ manifest[T].tpe <:< manifest[AnyRef].tpe,
+ !(manifest[T].tpe <:< manifest[AnyVal].tpe)
) foreach (assert(_, "assertAnyRef"))
-
+
def assertAnyVal[T: Manifest] = List(
- manifest[T] <:< manifest[Any],
- !(manifest[T] <:< manifest[AnyRef]),
- manifest[T] <:< manifest[AnyVal]
+ manifest[T].tpe <:< manifest[Any].tpe,
+ !(manifest[T].tpe <:< manifest[AnyRef].tpe),
+ manifest[T].tpe <:< manifest[AnyVal].tpe
) foreach (assert(_, "assertAnyVal"))
-
+
def assertSameType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SAME, "assertSameType")
def assertSuperType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SUPER, "assertSuperType")
def assertSubType[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == SUB, "assertSubType")
def assertNoRelationship[T: Manifest, U: Manifest] = assert(typeCompare[T, U] == NONE, "assertNoRelationship")
-
+
def testVariancesVia[T: Manifest, U: Manifest] = assert(
- typeCompare[T, U] == SUB &&
+ typeCompare[T, U] == SUB &&
showsCovariance[T, U, List] &&
showsInvariance[T, U, Set],
"testVariancesVia"
)
-
+
def runAllTests = {
assertAnyVal[AnyVal]
assertAnyVal[Unit]
- assertAnyVal[Int]
- assertAnyVal[Double]
+ assertAnyVal[Int]
+ assertAnyVal[Double]
assertAnyVal[Boolean]
assertAnyVal[Char]
-
+
assertAnyRef[AnyRef]
assertAnyRef[java.lang.Object]
assertAnyRef[java.lang.Integer]
@@ -103,7 +96,7 @@ object Test
assertAnyRef[String]
assertAnyRef[scala.List[String]]
assertAnyRef[scala.List[_]]
-
+
// variance doesn't work yet
// testVariancesVia[String, Any]
// testVariancesVia[String, AnyRef]
@@ -111,11 +104,11 @@ object Test
assertSubType[List[String], List[Any]]
assertSubType[List[String], List[AnyRef]]
assertNoRelationship[List[String], List[AnyVal]]
-
+
assertSubType[List[Int], List[Any]]
assertSubType[List[Int], List[AnyVal]]
assertNoRelationship[List[Int], List[AnyRef]]
-
+
// Nothing
assertSubType[Nothing, Any]
assertSubType[Nothing, AnyVal]
@@ -124,7 +117,7 @@ object Test
assertSubType[Nothing, List[String]]
assertSubType[Nothing, Null]
assertSameType[Nothing, Nothing]
-
+
// Null
assertSubType[Null, Any]
assertNoRelationship[Null, AnyVal]
@@ -133,7 +126,7 @@ object Test
assertSubType[Null, List[String]]
assertSameType[Null, Null]
assertSuperType[Null, Nothing]
-
+
// Any
assertSameType[Any, Any]
assertSuperType[Any, AnyVal]
@@ -142,7 +135,7 @@ object Test
assertSuperType[Any, List[String]]
assertSuperType[Any, Null]
assertSuperType[Any, Nothing]
-
+
// Misc unrelated types
assertNoRelationship[Unit, AnyRef]
assertNoRelationship[Unit, Int]