diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-12-02 16:31:33 +0100 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-12-10 16:02:45 +0100 |
commit | 4c899ea34c01eebf1215abd579d11393cf20a487 (patch) | |
tree | 2b730c5274281f94b216f7f59a2ccfb7ef82160c /test | |
parent | 4be6ea147a7d8f300c1e6db2a216b50fe8cf5dc7 (diff) | |
download | scala-4c899ea34c01eebf1215abd579d11393cf20a487.tar.gz scala-4c899ea34c01eebf1215abd579d11393cf20a487.tar.bz2 scala-4c899ea34c01eebf1215abd579d11393cf20a487.zip |
Refactor Holes and Reifiers slices of Quasiquotes cake
This commit performs a number of preliminary refactoring needed to
implement unliftable:
1. Replace previous inheritance-heavy implementation of Holes with
similar but much simpler one. Holes are now split into two different
categories: ApplyHole and UnapplyHole which correspondingly represent
information about holes in construction and deconstruction quasiquotes.
2. Make Placeholders extract holes rather than their field values. This
is required to be able to get additional mode-specific information
from holes (e.g. only ApplyHoles have types).
3. Bring ApplyReifier & UnapplyReifier even closer to the future where
there is just a single base Reifier with mode parameter.
Along the way a few bugs were fixed:
1. SI-7980 SI-7996 fail with nice error on bottom types splices
2. Use asSeenFrom instead of typeArguments in parseCardinality.
This fixes a crash if T <:< Iterable[Tree] but does not itself
have any type arguments.
3. Fix spurious error message on splicing of Lists through Liftable[List[T]]
Diffstat (limited to 'test')
-rw-r--r-- | test/files/neg/si7980.check | 4 | ||||
-rw-r--r-- | test/files/neg/si7980.scala | 8 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/ErrorProps.scala | 14 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/LiftableProps.scala | 10 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/TermConstructionProps.scala | 5 |
5 files changed, 41 insertions, 0 deletions
diff --git a/test/files/neg/si7980.check b/test/files/neg/si7980.check new file mode 100644 index 0000000000..b085cabf1d --- /dev/null +++ b/test/files/neg/si7980.check @@ -0,0 +1,4 @@ +si7980.scala:7: error: Can't splice Nothing, bottom type values often indicate programmer mistake + println(q"class ${Name(X)} { }") + ^ +one error found diff --git a/test/files/neg/si7980.scala b/test/files/neg/si7980.scala new file mode 100644 index 0000000000..b21907de54 --- /dev/null +++ b/test/files/neg/si7980.scala @@ -0,0 +1,8 @@ +object Test extends App { + import scala.reflect.runtime.universe._ + def Name[T:TypeTag](name:String): T = implicitly[TypeTag[T]] match { + case t => newTypeName(name).asInstanceOf[T] + } + val X = "ASDF" + println(q"class ${Name(X)} { }") +} diff --git a/test/files/scalacheck/quasiquotes/ErrorProps.scala b/test/files/scalacheck/quasiquotes/ErrorProps.scala index adad48fcdf..92d299bede 100644 --- a/test/files/scalacheck/quasiquotes/ErrorProps.scala +++ b/test/files/scalacheck/quasiquotes/ErrorProps.scala @@ -172,6 +172,20 @@ object ErrorProps extends QuasiquoteProperties("errors") { val q"$m1 $m2 def foo" = EmptyTree """) + property("can't splice values of Null") = fails( + "Can't splice Null, bottom type values often indicate programmer mistake", + """ + val n = null + q"$n" + """) + + property("can't splice values of Nothing") = fails( + "Can't splice Nothing, bottom type values often indicate programmer mistake", + """ + def n = ??? + q"$n" + """) + // // 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/LiftableProps.scala b/test/files/scalacheck/quasiquotes/LiftableProps.scala index 1271e1accd..2173337edd 100644 --- a/test/files/scalacheck/quasiquotes/LiftableProps.scala +++ b/test/files/scalacheck/quasiquotes/LiftableProps.scala @@ -76,4 +76,14 @@ object LiftableProps extends QuasiquoteProperties("liftable") { val const = Constant(0) assert(q"$const" ≈ q"0") } + + property("lift list variants") = test { + val lst = List(1, 2) + val immutable = q"$scalapkg.collection.immutable" + assert(q"$lst" ≈ q"$immutable.List(1, 2)") + assert(q"f(..$lst)" ≈ q"f(1, 2)") + val llst = List(List(1), List(2)) + assert(q"f(..$llst)" ≈ q"f($immutable.List(1), $immutable.List(2))") + assert(q"f(...$llst)" ≈ q"f(1)(2)") + } }
\ No newline at end of file diff --git a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala index 338c379fc3..6fb05ff9a4 100644 --- a/test/files/scalacheck/quasiquotes/TermConstructionProps.scala +++ b/test/files/scalacheck/quasiquotes/TermConstructionProps.scala @@ -204,6 +204,11 @@ object TermConstructionProps extends QuasiquoteProperties("term construction") { assert(q"f(${if (true) q"a" else q"b"})" ≈ q"f(a)") } + property("splice iterable of non-parametric type") = test { + object O extends Iterable[Tree] { def iterator = List(q"foo").iterator } + q"f(..$O)" + } + property("SI-8016") = test { val xs = q"1" :: q"2" :: Nil assertEqAst(q"..$xs", "{1; 2}") |