diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-12-16 17:12:29 +0100 |
---|---|---|
committer | Denys Shabalin <denys.shabalin@typesafe.com> | 2014-01-16 11:31:02 +0100 |
commit | 03e9e95f57b011336736d0e7ca64b90bb55e38a5 (patch) | |
tree | 6735441921b9aec044267794a266d7b68943ecd6 | |
parent | 6283c01462ff37755ebd06adaa633800105ba506 (diff) | |
download | scala-03e9e95f57b011336736d0e7ca64b90bb55e38a5.tar.gz scala-03e9e95f57b011336736d0e7ca64b90bb55e38a5.tar.bz2 scala-03e9e95f57b011336736d0e7ca64b90bb55e38a5.zip |
Test edge cases of literal lifting
Previously in some corner situation proper Liftable instance
might not have been resolved.
In particular q"${true}" and q"${""}" used to fail.
-rw-r--r-- | src/reflect/scala/reflect/api/StandardLiftables.scala | 20 | ||||
-rw-r--r-- | test/files/scalacheck/quasiquotes/LiftableProps.scala | 11 |
2 files changed, 21 insertions, 10 deletions
diff --git a/src/reflect/scala/reflect/api/StandardLiftables.scala b/src/reflect/scala/reflect/api/StandardLiftables.scala index 887a326d50..5a03996dd9 100644 --- a/src/reflect/scala/reflect/api/StandardLiftables.scala +++ b/src/reflect/scala/reflect/api/StandardLiftables.scala @@ -11,16 +11,16 @@ trait StandardLiftables { self: Universe => private def callCollection(name: Name)(args: List[Tree]) = callScala(nme.collection, nme.immutable, name)(args) private def liftAsLiteral[T]: Liftable[T] = Liftable { v => Literal(Constant(v)) } - implicit def liftByte[T <: Byte]: Liftable[T] = liftAsLiteral[T] - implicit def liftShort[T <: Short]: Liftable[T] = liftAsLiteral[T] - implicit def liftChar[T <: Char]: Liftable[T] = liftAsLiteral[T] - implicit def liftInt[T <: Int]: Liftable[T] = liftAsLiteral[T] - implicit def liftLong[T <: Long]: Liftable[T] = liftAsLiteral[T] - implicit def liftFloat[T <: Float]: Liftable[T] = liftAsLiteral[T] - implicit def liftDouble[T <: Double]: Liftable[T] = liftAsLiteral[T] - implicit def liftBoolean: Liftable[Boolean] = liftAsLiteral[Boolean] - implicit def liftUnit: Liftable[Unit] = liftAsLiteral[Unit] - implicit def liftString: Liftable[String] = liftAsLiteral[String] + implicit def liftByte[T <: Byte]: Liftable[T] = liftAsLiteral[T] + implicit def liftShort[T <: Short]: Liftable[T] = liftAsLiteral[T] + implicit def liftChar[T <: Char]: Liftable[T] = liftAsLiteral[T] + implicit def liftInt[T <: Int]: Liftable[T] = liftAsLiteral[T] + implicit def liftLong[T <: Long]: Liftable[T] = liftAsLiteral[T] + implicit def liftFloat[T <: Float]: Liftable[T] = liftAsLiteral[T] + implicit def liftDouble[T <: Double]: Liftable[T] = liftAsLiteral[T] + implicit def liftBoolean[T <: Boolean]: Liftable[T] = liftAsLiteral[T] + implicit def liftUnit: Liftable[Unit] = liftAsLiteral[Unit] + implicit def liftString[T <: String]: Liftable[T] = liftAsLiteral[T] implicit def liftScalaSymbol: Liftable[scala.Symbol] = Liftable { v => callScala(nme.Symbol)(Literal(Constant(v.name)) :: Nil) diff --git a/test/files/scalacheck/quasiquotes/LiftableProps.scala b/test/files/scalacheck/quasiquotes/LiftableProps.scala index 4fec89f191..bd631b8734 100644 --- a/test/files/scalacheck/quasiquotes/LiftableProps.scala +++ b/test/files/scalacheck/quasiquotes/LiftableProps.scala @@ -5,51 +5,62 @@ object LiftableProps extends QuasiquoteProperties("liftable") { property("splice byte") = test { val c: Byte = 0 assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${0: Byte}" ≈ Literal(Constant(c))) } property("splice short") = test { val c: Short = 0 assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${0: Short}" ≈ Literal(Constant(c))) } property("splice char") = test { val c: Char = 'c' assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${'c'}" ≈ Literal(Constant(c))) } property("splice int") = test { val c: Int = 0 assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${0: Int}" ≈ Literal(Constant(c))) } property("splice long") = test { val c: Long = 0 assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${0: Long}" ≈ Literal(Constant(c))) } property("splice float") = test { val c: Float = 0.0f assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${0.0f: Float}" ≈ Literal(Constant(c))) } property("splice double") = test { val c: Double = 0.0 assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${0.0: Double}" ≈ Literal(Constant(c))) } property("splice boolean") = test { val c: Boolean = false assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${true}" ≈ Literal(Constant(true))) + assert(q"${false}" ≈ Literal(Constant(false))) } property("splice string") = test { val c: String = "s" assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${"s"}" ≈ Literal(Constant(c))) } property("splice unit") = test { val c: Unit = () assert(q"$c" ≈ Literal(Constant(c))) + assert(q"${()}" ≈ Literal(Constant(c))) } property("lift symbol") = test { |