File tree 5 files changed +16
-2
lines changed
compiler/src/dotty/tools/dotc/quoted
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
3
3
import dotty .tools .dotc .ast .Trees ._
4
4
import dotty .tools .dotc .ast .tpd
5
5
import dotty .tools .dotc .core .Constants ._
6
- import dotty .tools .dotc .core .Contexts ._
7
6
import dotty .tools .dotc .printing .RefinedPrinter
8
7
9
8
import scala .quoted .Expr
10
9
import scala .quoted .Liftable .ConstantExpr
10
+ import scala .runtime .BoxedUnit
11
11
import scala .runtime .quoted ._
12
12
13
13
/** Default runners for quoted expressions */
@@ -23,7 +23,8 @@ object Runners {
23
23
implicit val ctx = new QuoteDriver ().initCtx
24
24
ctx.settings.color.update(" never" )
25
25
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 )
27
28
case _ => new QuoteDriver ().show(expr)
28
29
}
29
30
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ object Liftable {
22
22
override def toString : String = s " Expr( $value) "
23
23
}
24
24
25
+ implicit def UnitIsLiftable : Liftable [Unit ] = (x : Unit ) => new ConstantExpr (x)
25
26
implicit def BooleanIsLiftable : Liftable [Boolean ] = (x : Boolean ) => new ConstantExpr (x)
26
27
implicit def ByteLiftable : Liftable [Byte ] = (x : Byte ) => new ConstantExpr (x)
27
28
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 {
33
33
(1.0f : Expr [Float ])
34
34
(1.0 : Expr [Double ])
35
35
(" abc" : Expr [String ])
36
+ ((): Expr [Unit ])
36
37
37
38
val xs : Expr [List [Int ]] = 1 :: 2 :: 3 :: Nil
38
39
}
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