summaryrefslogtreecommitdiff
path: root/test/files/scalacheck
diff options
context:
space:
mode:
authorDenys Shabalin <denys.shabalin@typesafe.com>2014-01-22 19:49:21 +0100
committerDenys Shabalin <denys.shabalin@typesafe.com>2014-01-23 13:59:06 +0100
commitadf990ac516d8e04c725a4c7be7c23bdbf922ffa (patch)
tree33039f07740854ed2b6e5ffd1d3bf8624f040294 /test/files/scalacheck
parent01f9ab52111712a6f4bc677415e9ad7a3bfe41a2 (diff)
downloadscala-adf990ac516d8e04c725a4c7be7c23bdbf922ffa.tar.gz
scala-adf990ac516d8e04c725a4c7be7c23bdbf922ffa.tar.bz2
scala-adf990ac516d8e04c725a4c7be7c23bdbf922ffa.zip
SI-7275 allow flattening of blocks with ..$
This commit extends current splicing rules to allow flattening of trees into other trees. Without such support it is impossible to correctly create vals with patterns and use it in other location as they could expand into multiple-statement blocks: scala> q"val (a, b) = (1, 2)" res0: reflect.runtime.universe.Tree = { <synthetic> <artifact> private[this] val x$1 = scala.Tuple2(1, 2): @scala.unchecked match { case scala.Tuple2((a @ _), (b @ _)) => scala.Tuple2(a, b) }; val a = x$1._1; val b = x$1._2; () } scala> q"..$res0; println(a + b)" res1: reflect.runtime.universe.Tree = { <synthetic> <artifact> private[this] val x$1 = scala.Tuple2(1, 2): @scala.unchecked match { case scala.Tuple2((a @ _), (b @ _)) => scala.Tuple2(a, b) }; val a = x$1._1; val b = x$1._2; println(a.$plus(b)) }
Diffstat (limited to 'test/files/scalacheck')
-rw-r--r--test/files/scalacheck/quasiquotes/ErrorProps.scala16
-rw-r--r--test/files/scalacheck/quasiquotes/TermConstructionProps.scala39
2 files changed, 40 insertions, 15 deletions
diff --git a/test/files/scalacheck/quasiquotes/ErrorProps.scala b/test/files/scalacheck/quasiquotes/ErrorProps.scala
index 92d299bede..3a66574c7d 100644
--- a/test/files/scalacheck/quasiquotes/ErrorProps.scala
+++ b/test/files/scalacheck/quasiquotes/ErrorProps.scala
@@ -52,13 +52,6 @@ object ErrorProps extends QuasiquoteProperties("errors") {
StringContext("\"", "\"").q(x)
""")
- property("expected different cardinality") = fails(
- "Can't splice List[reflect.runtime.universe.Tree] with ..., consider using ..",
- """
- val args: List[Tree] = Nil
- q"f(...$args)"
- """)
-
property("non-liftable type ..") = fails(
"Can't splice List[StringBuilder] with .., consider omitting the dots or providing an implicit instance of Liftable[StringBuilder]",
"""
@@ -90,13 +83,6 @@ object ErrorProps extends QuasiquoteProperties("errors") {
q"$xs"
""")
- property("use zero card") = fails(
- "Can't splice reflect.runtime.universe.Tree with .., consider omitting the dots",
- """
- val t = EmptyTree
- q"f(..$t)"
- """)
-
property("not liftable or natively supported") = fails(
"Can't splice StringBuilder, consider providing an implicit instance of Liftable[StringBuilder]",
"""
@@ -188,4 +174,4 @@ object ErrorProps extends QuasiquoteProperties("errors") {
// // Make sure a nice error is reported in this case
// { import Flag._; val mods = NoMods; q"lazy $mods val x: Int" }
-} \ No newline at end of file
+}
diff --git a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
index 38fbfa9f7f..7bbd7a85b3 100644
--- a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
+++ b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala
@@ -229,4 +229,43 @@ object TermConstructionProps extends QuasiquoteProperties("term construction") {
val q"($a, $b) => $_" = q"_ + _"
assert(a.name != b.name)
}
+
+ property("SI-7275 a") = test {
+ val t = q"stat1; stat2"
+ assertEqAst(q"..$t", "{stat1; stat2}")
+ }
+
+ property("SI-7275 b") = test {
+ def f(t: Tree) = q"..$t"
+ assertEqAst(f(q"stat1; stat2"), "{stat1; stat2}")
+ }
+
+ property("SI-7275 c1") = test {
+ object O
+ implicit val liftO = Liftable[O.type] { _ => q"foo; bar" }
+ assertEqAst(q"f(..$O)", "f(foo, bar)")
+ }
+
+ property("SI-7275 c2") = test {
+ object O
+ implicit val liftO = Liftable[O.type] { _ => q"{ foo; bar }; { baz; bax }" }
+ assertEqAst(q"f(...$O)", "f(foo, bar)(baz, bax)")
+ }
+
+ property("SI-7275 d") = test {
+ val l = q"a; b" :: q"c; d" :: Nil
+ assertEqAst(q"f(...$l)", "f(a, b)(c, d)")
+ val l2: Iterable[Tree] = l
+ assertEqAst(q"f(...$l2)", "f(a, b)(c, d)")
+ }
+
+ property("SI-7275 e") = test {
+ val t = q"{ a; b }; { c; d }"
+ assertEqAst(q"f(...$t)", "f(a, b)(c, d)")
+ }
+
+ property("SI-7275 e2") = test {
+ val t = q"{ a; b }; c; d"
+ assertEqAst(q"f(...$t)", "f(a, b)(c)(d)")
+ }
}