summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDenys Shabalin <denys.shabalin@typesafe.com>2014-02-10 14:29:59 +0100
committerDenys Shabalin <denys.shabalin@typesafe.com>2014-02-10 14:44:27 +0100
commit2b67f8b94f9e95c5fb7be0e6d6c4718a6e045ec4 (patch)
tree437aa34986ad2b060b5ef52533a7f8abf5b199e4 /src
parent08e51dfec50842253afb87cc5ae3c7400dc18ced (diff)
downloadscala-2b67f8b94f9e95c5fb7be0e6d6c4718a6e045ec4.tar.gz
scala-2b67f8b94f9e95c5fb7be0e6d6c4718a6e045ec4.tar.bz2
scala-2b67f8b94f9e95c5fb7be0e6d6c4718a6e045ec4.zip
Make handling of tuples more consistent in quasi-quotes
On one hand we know that q"($expr)" is the same as q"$expr". On the other if we wrap it into a list and splice as q"(..$expr)" we get a Tuple1 constructor call which is inconsistent. This pull request fixes this inconsistency by making q"(..$expr)" being equivalent q"(${expr.head})" for single-element list. We also add support for matching of expressions as single-element tuples (similarly to blocks) and remove liftables and unliftables for Tuple1 (which aren't clearly defined any longer due to q"(foo)" == q"foo" invariant).
Diffstat (limited to 'src')
-rw-r--r--src/reflect/scala/reflect/api/StandardLiftables.scala6
-rw-r--r--src/reflect/scala/reflect/internal/BuildUtils.scala8
2 files changed, 6 insertions, 8 deletions
diff --git a/src/reflect/scala/reflect/api/StandardLiftables.scala b/src/reflect/scala/reflect/api/StandardLiftables.scala
index 5a03996dd9..6c2c8ca618 100644
--- a/src/reflect/scala/reflect/api/StandardLiftables.scala
+++ b/src/reflect/scala/reflect/api/StandardLiftables.scala
@@ -53,9 +53,6 @@ trait StandardLiftables { self: Universe =>
case right: Right[L, R] => lift(right)
}
- implicit def liftTuple1[T1](implicit liftT1: Liftable[T1]): Liftable[Tuple1[T1]] = Liftable { t =>
- SyntacticTuple(liftT1(t._1) :: Nil)
- }
implicit def liftTuple2[T1, T2](implicit liftT1: Liftable[T1], liftT2: Liftable[T2]): Liftable[Tuple2[T1, T2]] = Liftable { t =>
SyntacticTuple(liftT1(t._1) :: liftT2(t._2) :: Nil)
}
@@ -147,9 +144,6 @@ trait StandardLiftables { self: Universe =>
implicit def unliftType: Unliftable[Type] = Unliftable[Type] { case tt: TypeTree if tt.tpe != null => tt.tpe }
implicit def unliftConstant: Unliftable[Constant] = Unliftable[Constant] { case Literal(const) => const }
- implicit def unliftTuple1[T1](implicit UnliftT1: Unliftable[T1]): Unliftable[Tuple1[T1]] = Unliftable {
- case SyntacticTuple(UnliftT1(v1) :: Nil) => Tuple1(v1)
- }
implicit def unliftTuple2[T1, T2](implicit UnliftT1: Unliftable[T1], UnliftT2: Unliftable[T2]): Unliftable[Tuple2[T1, T2]] = Unliftable {
case SyntacticTuple(UnliftT1(v1) :: UnliftT2(v2) :: Nil) => Tuple2(v1, v2)
}
diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala
index c5581601de..738eb316f0 100644
--- a/src/reflect/scala/reflect/internal/BuildUtils.scala
+++ b/src/reflect/scala/reflect/internal/BuildUtils.scala
@@ -350,7 +350,7 @@ trait BuildUtils { self: SymbolTable =>
object SyntacticTuple extends SyntacticTupleExtractor {
def apply(args: List[Tree]): Tree = {
require(args.isEmpty || TupleClass(args.length).exists, s"Tuples with ${args.length} arity aren't supported")
- gen.mkTuple(args, flattenUnary = false)
+ gen.mkTuple(args)
}
def unapply(tree: Tree): Option[List[Tree]] = tree match {
@@ -360,6 +360,8 @@ trait BuildUtils { self: SymbolTable =>
if sym == TupleClass(args.length).companionModule
&& (targs.isEmpty || targs.length == args.length) =>
Some(args)
+ case _ if tree.isTerm =>
+ Some(tree :: Nil)
case _ =>
None
}
@@ -368,7 +370,7 @@ trait BuildUtils { self: SymbolTable =>
object SyntacticTupleType extends SyntacticTupleExtractor {
def apply(args: List[Tree]): Tree = {
require(args.isEmpty || TupleClass(args.length).exists, s"Tuples with ${args.length} arity aren't supported")
- gen.mkTupleType(args, flattenUnary = false)
+ gen.mkTupleType(args)
}
def unapply(tree: Tree): Option[List[Tree]] = tree match {
@@ -377,6 +379,8 @@ trait BuildUtils { self: SymbolTable =>
case MaybeTypeTreeOriginal(AppliedTypeTree(TupleClassRef(sym), args))
if sym == TupleClass(args.length) =>
Some(args)
+ case _ if tree.isType =>
+ Some(tree :: Nil)
case _ =>
None
}