Skip to content

Fix #3946: Add Unit lifter in quoted.Liftable #3977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/quoted/Runners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package dotty.tools.dotc.quoted
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Constants._
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.printing.RefinedPrinter

import scala.quoted.Expr
import scala.quoted.Liftable.ConstantExpr
import scala.runtime.BoxedUnit
import scala.runtime.quoted._

/** Default runners for quoted expressions */
Expand All @@ -23,7 +23,8 @@ object Runners {
implicit val ctx = new QuoteDriver().initCtx
ctx.settings.color.update("never")
val printer = new RefinedPrinter(ctx)
printer.toText(Literal(Constant(expr.value))).mkString(Int.MaxValue, false)
if (expr.value == BoxedUnit.UNIT) "()"
else printer.toText(Literal(Constant(expr.value))).mkString(Int.MaxValue, false)
case _ => new QuoteDriver().show(expr)
}

Expand Down
1 change: 1 addition & 0 deletions library/src/scala/quoted/Liftable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object Liftable {
override def toString: String = s"Expr($value)"
}

implicit def UnitIsLiftable: Liftable[Unit] = (x: Unit) => new ConstantExpr(x)
implicit def BooleanIsLiftable: Liftable[Boolean] = (x: Boolean) => new ConstantExpr(x)
implicit def ByteLiftable: Liftable[Byte] = (x: Byte) => new ConstantExpr(x)
implicit def CharIsLiftable: Liftable[Char] = (x: Char) => new ConstantExpr(x)
Expand Down
1 change: 1 addition & 0 deletions tests/pos/quote-liftable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object Test {
(1.0f: Expr[Float])
(1.0: Expr[Double])
("abc": Expr[String])
((): Expr[Unit])

val xs: Expr[List[Int]] = 1 :: 2 :: 3 :: Nil
}
2 changes: 2 additions & 0 deletions tests/run-with-compiler/i3946.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
()
()
9 changes: 9 additions & 0 deletions tests/run-with-compiler/i3946.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dotty.tools.dotc.quoted.Runners._
import scala.quoted._
object Test {
def main(args: Array[String]): Unit = {
val u: Expr[Unit] = ()
println(u.show)
println(u.run)
}
}