summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-09-27 12:27:52 -0700
committerEugene Burmako <xeno.by@gmail.com>2012-09-27 12:27:52 -0700
commit6b630ebb57306572e176a646e5bec7f3132ff18e (patch)
tree13d7657a501645355df9d7aa376f2daafc65f962 /test
parent1518604f72de56f05bfa95cd59ed39326178b042 (diff)
parentee1ca007c73d941c88c893637263b7d4b5fc842e (diff)
downloadscala-6b630ebb57306572e176a646e5bec7f3132ff18e.tar.gz
scala-6b630ebb57306572e176a646e5bec7f3132ff18e.tar.bz2
scala-6b630ebb57306572e176a646e5bec7f3132ff18e.zip
Merge pull request #1402 from scalamacros/topic/reflection
reflection and macro cleanup
Diffstat (limited to 'test')
-rw-r--r--test/files/run/macro-openmacros/Impls_Macros_1.scala3
-rw-r--r--test/files/run/macro-reify-nested-a/Impls_Macros_1.scala3
-rw-r--r--test/files/run/macro-reify-nested-b/Impls_Macros_1.scala3
-rw-r--r--test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala13
-rw-r--r--test/files/run/macro-reify-unreify/Macros_1.scala5
-rw-r--r--test/files/run/macro-sip19-revised/Impls_Macros_1.scala2
-rw-r--r--test/files/run/macro-sip19/Impls_Macros_1.scala2
-rw-r--r--test/files/run/macro-typecheck-macrosdisabled.check4
-rw-r--r--test/files/run/macro-typecheck-macrosdisabled2.check4
-rw-r--r--test/files/run/toolbox_console_reporter.check8
-rw-r--r--test/files/run/toolbox_console_reporter.scala35
-rw-r--r--test/files/run/toolbox_silent_reporter.scala4
-rw-r--r--test/files/run/toolbox_typecheck_macrosdisabled.check4
-rw-r--r--test/files/run/toolbox_typecheck_macrosdisabled2.check4
14 files changed, 53 insertions, 41 deletions
diff --git a/test/files/run/macro-openmacros/Impls_Macros_1.scala b/test/files/run/macro-openmacros/Impls_Macros_1.scala
index 38d46c5185..b863ac048b 100644
--- a/test/files/run/macro-openmacros/Impls_Macros_1.scala
+++ b/test/files/run/macro-openmacros/Impls_Macros_1.scala
@@ -4,8 +4,7 @@ object Macros {
def impl(c: Context): c.Expr[Unit] = {
// we're macros, so we can reflect against our source path
// so we don't need any partests to clean up after us!
- val c.CompilationUnit(file, _, _) = c.enclosingUnit
- val dir = file.getCanonicalFile.getParentFile
+ val dir = c.enclosingUnit.source.file.file.getCanonicalFile.getParentFile
def normalizePaths(s: String) = {
val base = (dir.getCanonicalPath + java.io.File.separator).replace('\\', '/')
var regex = """\Q%s\E""" format base
diff --git a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala
index ae2def2d3e..b4351c2c53 100644
--- a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala
+++ b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala
@@ -23,9 +23,10 @@ case class Utils[C <: Context]( c:C ) {
object QueryableMacros{
def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = {
import c.universe._
+ import treeBuild._
val element_type = implicitly[c.WeakTypeTag[S]].tpe
val foo = c.Expr[ru.Expr[Queryable[S]]](
- c.reifyTree( c.runtimeUniverse, EmptyTree, c.typeCheck(
+ c.reifyTree( mkRuntimeUniverseRef, EmptyTree, c.typeCheck(
Utils[c.type](c).removeDoubleReify(
Apply(Select(c.prefix.tree, newTermName( name )), List( projection.tree ))
).asInstanceOf[Tree]
diff --git a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala
index ae2def2d3e..b4351c2c53 100644
--- a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala
+++ b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala
@@ -23,9 +23,10 @@ case class Utils[C <: Context]( c:C ) {
object QueryableMacros{
def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = {
import c.universe._
+ import treeBuild._
val element_type = implicitly[c.WeakTypeTag[S]].tpe
val foo = c.Expr[ru.Expr[Queryable[S]]](
- c.reifyTree( c.runtimeUniverse, EmptyTree, c.typeCheck(
+ c.reifyTree( mkRuntimeUniverseRef, EmptyTree, c.typeCheck(
Utils[c.type](c).removeDoubleReify(
Apply(Select(c.prefix.tree, newTermName( name )), List( projection.tree ))
).asInstanceOf[Tree]
diff --git a/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala b/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala
index b23a5c70e1..5330d0e32b 100644
--- a/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala
+++ b/test/files/run/macro-reify-splice-outside-reify/Impls_Macros_1.scala
@@ -4,18 +4,7 @@ object Impls {
def foo(c: Ctx)(x: c.Expr[Int]) = {
val x1 = c.Expr[Int](c.resetAllAttrs(x.tree))
// was: c.literal(x1.splice)
- c.literal(eval(c)(x1))
- }
-
- private def eval[T](c: Ctx)(x: c.Expr[T]): T = {
- import scala.reflect.runtime.{universe => ru}
- val mirror = ru.runtimeMirror(c.libraryClassLoader)
- import scala.tools.reflect.ToolBox
- val toolBox = mirror.mkToolBox()
- val importer = ru.mkImporter(c.universe).asInstanceOf[ru.Importer { val from: c.universe.type }]
- val tree = c.resetAllAttrs(x.tree.duplicate)
- val imported = importer.importTree(tree)
- toolBox.eval(imported).asInstanceOf[T]
+ c.literal(c.eval(x1))
}
}
diff --git a/test/files/run/macro-reify-unreify/Macros_1.scala b/test/files/run/macro-reify-unreify/Macros_1.scala
index 620a929210..9f04c13014 100644
--- a/test/files/run/macro-reify-unreify/Macros_1.scala
+++ b/test/files/run/macro-reify-unreify/Macros_1.scala
@@ -6,9 +6,10 @@ object Macros {
object Impls {
def foo(c: Ctx)(s: c.Expr[String]) = {
import c.universe._
+ import treeBuild._
- val world = c.reifyTree(c.runtimeUniverse, EmptyTree, s.tree)
- val greeting = c.reifyTree(c.runtimeUniverse, EmptyTree, c.typeCheck(Apply(Select(Literal(Constant("hello ")), newTermName("$plus")), List(c.unreifyTree(world)))))
+ val world = c.reifyTree(mkRuntimeUniverseRef, EmptyTree, s.tree)
+ val greeting = c.reifyTree(mkRuntimeUniverseRef, EmptyTree, c.typeCheck(Apply(Select(Literal(Constant("hello ")), newTermName("$plus")), List(c.unreifyTree(world)))))
val typedGreeting = c.Expr[String](greeting)
c.universe.reify {
diff --git a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala
index 0793696fd4..5f3f61ca3f 100644
--- a/test/files/run/macro-sip19-revised/Impls_Macros_1.scala
+++ b/test/files/run/macro-sip19-revised/Impls_Macros_1.scala
@@ -8,7 +8,7 @@ object Macros {
val outer = c.Expr[SourceLocation](if (!inscope.isEmpty) inscope else Literal(Constant(null)))
val Apply(fun, args) = c.enclosingImplicits(0)._2
- val fileName = fun.pos.fileInfo.getName
+ val fileName = fun.pos.source.file.file.getName
val line = fun.pos.line
val charOffset = fun.pos.point
c.universe.reify { SourceLocation1(outer.splice, c.literal(fileName).splice, c.literal(line).splice, c.literal(charOffset).splice) }
diff --git a/test/files/run/macro-sip19/Impls_Macros_1.scala b/test/files/run/macro-sip19/Impls_Macros_1.scala
index f89e51f560..535ec2ccf0 100644
--- a/test/files/run/macro-sip19/Impls_Macros_1.scala
+++ b/test/files/run/macro-sip19/Impls_Macros_1.scala
@@ -4,7 +4,7 @@ object Macros {
def impl(c: Context) = {
import c.universe._
val Apply(fun, args) = c.enclosingImplicits(0)._2
- val fileName = fun.pos.fileInfo.getName
+ val fileName = fun.pos.source.file.file.getName
val line = fun.pos.line
val charOffset = fun.pos.point
c.universe.reify { SourceLocation(c.literal(fileName).splice, c.literal(line).splice, c.literal(charOffset).splice) }
diff --git a/test/files/run/macro-typecheck-macrosdisabled.check b/test/files/run/macro-typecheck-macrosdisabled.check
index 719c6a2ef2..29a881f8b1 100644
--- a/test/files/run/macro-typecheck-macrosdisabled.check
+++ b/test/files/run/macro-typecheck-macrosdisabled.check
@@ -7,7 +7,7 @@
$treecreator1.super.<init>();
()
};
- def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.MirrorOf[U]): U#Tree = {
+ def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Tree = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.Literal.apply($u.Constant.apply(2))
@@ -20,7 +20,7 @@
$typecreator2.super.<init>();
()
};
- def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.MirrorOf[U]): U#Type = {
+ def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.ConstantType.apply($u.Constant.apply(2))
diff --git a/test/files/run/macro-typecheck-macrosdisabled2.check b/test/files/run/macro-typecheck-macrosdisabled2.check
index 1fd422083c..7bdd1d6a3a 100644
--- a/test/files/run/macro-typecheck-macrosdisabled2.check
+++ b/test/files/run/macro-typecheck-macrosdisabled2.check
@@ -7,7 +7,7 @@
$treecreator1.super.<init>();
()
};
- def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.MirrorOf[U]): U#Tree = {
+ def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Tree = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.Apply.apply($u.Select.apply($u.Select.apply($u.build.Ident($m.staticPackage("scala")), $u.newTermName("Array")), $u.newTermName("apply")), scala.collection.immutable.List.apply[$u.Literal]($u.Literal.apply($u.Constant.apply(2))))
@@ -20,7 +20,7 @@
$typecreator2.super.<init>();
()
};
- def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.MirrorOf[U]): U#Type = {
+ def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.TypeRef.apply($u.ThisType.apply($m.staticPackage("scala").asModule.moduleClass), $m.staticClass("scala.Array"), scala.collection.immutable.List.apply[$u.Type]($m.staticClass("scala.Int").asType.toTypeConstructor))
diff --git a/test/files/run/toolbox_console_reporter.check b/test/files/run/toolbox_console_reporter.check
index e69de29bb2..1395c68740 100644
--- a/test/files/run/toolbox_console_reporter.check
+++ b/test/files/run/toolbox_console_reporter.check
@@ -0,0 +1,8 @@
+hello
+============compiler console=============
+warning: method foo in object Utils is deprecated: test
+
+=========================================
+============compiler messages============
+Info(NoPosition,method foo in object Utils is deprecated: test,WARNING)
+=========================================
diff --git a/test/files/run/toolbox_console_reporter.scala b/test/files/run/toolbox_console_reporter.scala
index a57dea38a8..d672ccb9cb 100644
--- a/test/files/run/toolbox_console_reporter.scala
+++ b/test/files/run/toolbox_console_reporter.scala
@@ -1,16 +1,29 @@
import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{universe => ru}
+import scala.reflect.runtime.{currentMirror => cm}
+import scala.tools.reflect.{ToolBox, mkConsoleFrontEnd}
object Test extends App {
- // todo. cannot test this unfortunately, because ConsoleFrontEnd grabs Console.out too early
- // todo. and isn't affected by Console.setOut employed by partest to intercept output
+ val oldErr = Console.err;
+ val baos = new java.io.ByteArrayOutputStream();
+ Console.setErr(new java.io.PrintStream(baos));
+ try {
+ val toolbox = cm.mkToolBox(frontEnd = mkConsoleFrontEnd(), options = "-deprecation")
+ toolbox.eval(reify{
+ object Utils {
+ @deprecated("test", "2.10.0")
+ def foo { println("hello") }
+ }
- //val toolbox = mkToolBox(frontEnd = mkConsoleFrontEnd(), options = "-deprecation")
- //toolbox.eval(reify{
- // object Utils {
- // @deprecated("test", "2.10.0")
- // def foo { println("hello") }
- // }
- //
- // Utils.foo
- //})
+ Utils.foo
+ }.tree)
+ println("============compiler console=============")
+ println(baos.toString);
+ println("=========================================")
+ println("============compiler messages============")
+ toolbox.frontEnd.infos.foreach(println(_))
+ println("=========================================")
+ } finally {
+ Console.setErr(oldErr);
+ }
} \ No newline at end of file
diff --git a/test/files/run/toolbox_silent_reporter.scala b/test/files/run/toolbox_silent_reporter.scala
index 15f559d605..03b1d6defa 100644
--- a/test/files/run/toolbox_silent_reporter.scala
+++ b/test/files/run/toolbox_silent_reporter.scala
@@ -1,10 +1,10 @@
import scala.reflect.runtime.universe._
import scala.reflect.runtime.{universe => ru}
import scala.reflect.runtime.{currentMirror => cm}
-import scala.tools.reflect.ToolBox
+import scala.tools.reflect.{ToolBox, mkSilentFrontEnd}
object Test extends App {
- val toolbox = cm.mkToolBox(options = "-deprecation")
+ val toolbox = cm.mkToolBox(options = "-deprecation", frontEnd = mkSilentFrontEnd())
toolbox.eval(reify{
object Utils {
@deprecated("test", "2.10.0")
diff --git a/test/files/run/toolbox_typecheck_macrosdisabled.check b/test/files/run/toolbox_typecheck_macrosdisabled.check
index 9e997dafed..688f37927c 100644
--- a/test/files/run/toolbox_typecheck_macrosdisabled.check
+++ b/test/files/run/toolbox_typecheck_macrosdisabled.check
@@ -16,7 +16,7 @@
$treecreator1.super.<init>();
()
};
- def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.MirrorOf[U]): U#Tree = {
+ def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Tree = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.Literal.apply($u.Constant.apply(2))
@@ -29,7 +29,7 @@
$typecreator2.super.<init>();
()
};
- def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.MirrorOf[U]): U#Type = {
+ def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.ConstantType.apply($u.Constant.apply(2))
diff --git a/test/files/run/toolbox_typecheck_macrosdisabled2.check b/test/files/run/toolbox_typecheck_macrosdisabled2.check
index 16c8d6c397..f5c9b6eeab 100644
--- a/test/files/run/toolbox_typecheck_macrosdisabled2.check
+++ b/test/files/run/toolbox_typecheck_macrosdisabled2.check
@@ -16,7 +16,7 @@
$treecreator1.super.<init>();
()
};
- def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.MirrorOf[U]): U#Tree = {
+ def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Tree = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.Apply.apply($u.Select.apply($u.Select.apply($u.build.Ident($m.staticPackage("scala")), $u.newTermName("Array")), $u.newTermName("apply")), scala.collection.immutable.List.apply[$u.Literal]($u.Literal.apply($u.Constant.apply(2))))
@@ -29,7 +29,7 @@
$typecreator2.super.<init>();
()
};
- def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.MirrorOf[U]): U#Type = {
+ def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.TypeRef.apply($u.ThisType.apply($m.staticPackage("scala").asModule.moduleClass), $m.staticClass("scala.Array"), scala.collection.immutable.List.apply[$u.Type]($m.staticClass("scala.Int").asType.toTypeConstructor))