File tree Expand file tree Collapse file tree 5 files changed +16
-2
lines changed
compiler/src/dotty/tools/dotc/quoted Expand file tree Collapse file tree 5 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,11 @@ package dotty.tools.dotc.quoted
33import dotty .tools .dotc .ast .Trees ._
44import dotty .tools .dotc .ast .tpd
55import dotty .tools .dotc .core .Constants ._
6- import dotty .tools .dotc .core .Contexts ._
76import dotty .tools .dotc .printing .RefinedPrinter
87
98import scala .quoted .Expr
109import scala .quoted .Liftable .ConstantExpr
10+ import scala .runtime .BoxedUnit
1111import scala .runtime .quoted ._
1212
1313/** Default runners for quoted expressions */
@@ -23,7 +23,8 @@ object Runners {
2323 implicit val ctx = new QuoteDriver ().initCtx
2424 ctx.settings.color.update(" never" )
2525 val printer = new RefinedPrinter (ctx)
26- printer.toText(Literal (Constant (expr.value))).mkString(Int .MaxValue , false )
26+ if (expr.value == BoxedUnit .UNIT ) " ()"
27+ else printer.toText(Literal (Constant (expr.value))).mkString(Int .MaxValue , false )
2728 case _ => new QuoteDriver ().show(expr)
2829 }
2930
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ object Liftable {
2222 override def toString : String = s " Expr( $value) "
2323 }
2424
25+ implicit def UnitIsLiftable : Liftable [Unit ] = (x : Unit ) => new ConstantExpr (x)
2526 implicit def BooleanIsLiftable : Liftable [Boolean ] = (x : Boolean ) => new ConstantExpr (x)
2627 implicit def ByteLiftable : Liftable [Byte ] = (x : Byte ) => new ConstantExpr (x)
2728 implicit def CharIsLiftable : Liftable [Char ] = (x : Char ) => new ConstantExpr (x)
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ object Test {
3333 (1.0f : Expr [Float ])
3434 (1.0 : Expr [Double ])
3535 (" abc" : Expr [String ])
36+ ((): Expr [Unit ])
3637
3738 val xs : Expr [List [Int ]] = 1 :: 2 :: 3 :: Nil
3839}
Original file line number Diff line number Diff line change 1+ ()
2+ ()
Original file line number Diff line number Diff line change 1+ import dotty .tools .dotc .quoted .Runners ._
2+ import scala .quoted ._
3+ object Test {
4+ def main (args : Array [String ]): Unit = {
5+ val u : Expr [Unit ] = ()
6+ println(u.show)
7+ println(u.run)
8+ }
9+ }
You can’t perform that action at this time.
0 commit comments