Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 03e9e95f57b011336736d0e7ca64b90bb55e38a5 1 parent 6283c01
@densh densh authored densh committed
View
20 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)
View
11 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 {
Please sign in to comment.
Something went wrong with that request. Please try again.