summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kotelnikov <evgeny.kotelnikov@gmail.com>2013-01-19 17:42:12 +0400
committerEugene Burmako <xeno.by@gmail.com>2013-02-07 18:56:20 +0100
commit96b0eff51e18a1abd9761451e08e63c9a3eb9ea6 (patch)
treec7706349969b570274dbb9259e29e9c4c3473471
parent3d318be51f8e8cdec314565920327486212f5020 (diff)
downloadscala-96b0eff51e18a1abd9761451e08e63c9a3eb9ea6.tar.gz
scala-96b0eff51e18a1abd9761451e08e63c9a3eb9ea6.tar.bz2
scala-96b0eff51e18a1abd9761451e08e63c9a3eb9ea6.zip
SI-5824 Fix crashes in reify with _*
Reification crashes if "foo: _*" construct is used. This happens besause type tree is represented either with TypeTree, or with Ident (present case), and `toPreTyperTypedOrAnnotated' only matches of the former. The fix is to cover the latter too. A test is included.
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenTrees.scala2
-rw-r--r--src/compiler/scala/reflect/reify/phases/Reshape.scala12
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala7
-rw-r--r--test/files/run/t5824.check1
-rw-r--r--test/files/run/t5824.scala8
5 files changed, 25 insertions, 5 deletions
diff --git a/src/compiler/scala/reflect/reify/codegen/GenTrees.scala b/src/compiler/scala/reflect/reify/codegen/GenTrees.scala
index 31974b5b76..45865268cd 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenTrees.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenTrees.scala
@@ -177,7 +177,7 @@ trait GenTrees {
// then we can reify the scrutinee as a symless AST and that will definitely be hygienic
// why? because then typechecking of a scrutinee doesn't depend on the environment external to the quasiquote
// otherwise we need to reify the corresponding type
- if (sym.isLocalToReifee || tpe.isLocalToReifee)
+ if (sym.isLocalToReifee || tpe.isLocalToReifee || treeInfo.isWildcardStarType(tree))
reifyProduct(tree)
else {
if (reifyDebug) println("reifying bound type %s (underlying type is %s)".format(sym, tpe))
diff --git a/src/compiler/scala/reflect/reify/phases/Reshape.scala b/src/compiler/scala/reflect/reify/phases/Reshape.scala
index 1b7509fdbe..7406f5d02d 100644
--- a/src/compiler/scala/reflect/reify/phases/Reshape.scala
+++ b/src/compiler/scala/reflect/reify/phases/Reshape.scala
@@ -188,8 +188,12 @@ trait Reshape {
}
private def toPreTyperTypedOrAnnotated(tree: Tree): Tree = tree match {
- case ty @ Typed(expr1, tt @ TypeTree()) =>
+ case ty @ Typed(expr1, tpt) =>
if (reifyDebug) println("reify typed: " + tree)
+ val original = tpt match {
+ case tt @ TypeTree() => tt.original
+ case tpt => tpt
+ }
val annotatedArg = {
def loop(tree: Tree): Tree = tree match {
case annotated1 @ Annotated(ann, annotated2 @ Annotated(_, _)) => loop(annotated2)
@@ -197,15 +201,15 @@ trait Reshape {
case _ => EmptyTree
}
- loop(tt.original)
+ loop(original)
}
if (annotatedArg != EmptyTree) {
if (annotatedArg.isType) {
if (reifyDebug) println("verdict: was an annotated type, reify as usual")
ty
} else {
- if (reifyDebug) println("verdict: was an annotated value, equivalent is " + tt.original)
- toPreTyperTypedOrAnnotated(tt.original)
+ if (reifyDebug) println("verdict: was an annotated value, equivalent is " + original)
+ toPreTyperTypedOrAnnotated(original)
}
} else {
if (reifyDebug) println("verdict: wasn't annotated, reify as usual")
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index 98c1afb323..44dd92e62b 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -431,6 +431,13 @@ abstract class TreeInfo {
case _ => false
}
+ /** Is the argument a wildcard star type of the form `_*`?
+ */
+ def isWildcardStarType(tree: Tree): Boolean = tree match {
+ case Ident(tpnme.WILDCARD_STAR) => true
+ case _ => false
+ }
+
/** Is this pattern node a catch-all (wildcard or variable) pattern? */
def isDefaultCase(cdef: CaseDef) = cdef match {
case CaseDef(pat, EmptyTree, _) => isWildcardArg(pat)
diff --git a/test/files/run/t5824.check b/test/files/run/t5824.check
new file mode 100644
index 0000000000..3774da60e5
--- /dev/null
+++ b/test/files/run/t5824.check
@@ -0,0 +1 @@
+a b c
diff --git a/test/files/run/t5824.scala b/test/files/run/t5824.scala
new file mode 100644
index 0000000000..2ad169e2d1
--- /dev/null
+++ b/test/files/run/t5824.scala
@@ -0,0 +1,8 @@
+import scala.reflect.runtime.universe._
+import scala.tools.reflect.Eval
+
+object Test extends App {
+ reify {
+ println("%s %s %s".format(List("a", "b", "c"): _*))
+ }.eval
+}