Skip to content

Commit c05247a

Browse files
committed
Make {Expr|Type}.show extension methods
1 parent 574fd0c commit c05247a

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

library/src-bootstrapped/scala/quoted/Type.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import scala.runtime.quoted.Unpickler.Pickled
66

77
sealed abstract class Type[T <: AnyKind] {
88
type `$splice` = T
9-
10-
/** Show a source code like representation of this type */
11-
final def show(implicit toolbox: Toolbox): String = toolbox.show(this.asInstanceOf[Type[Any]])
129
}
1310

1411
/** Some basic type tags, currently incomplete */
1512
object Type {
1613

14+
implicit class TypeOps[T](tpe: Type[T]) {
15+
/** Show a source code like representation of this type */
16+
def show(implicit toolbox: Toolbox): String = toolbox.show(tpe.asInstanceOf[Type[Any]])
17+
}
18+
1719
implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
1820
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
1921
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]

library/src-non-bootstrapped/scala/quoted/Type.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ import scala.runtime.quoted.Unpickler.Pickled
66

77
sealed abstract class Type[T] {
88
type `$splice` = T
9-
10-
/** Show a source code like representation of this type */
11-
final def show(implicit toolbox: Toolbox): String = toolbox.show(this)
129
}
1310

1411
/** Some basic type tags, currently incomplete */
1512
object Type {
13+
14+
implicit class TypeOps[T](tpe: Type[T]) {
15+
/** Show a source code like representation of this type */
16+
def show(implicit toolbox: Toolbox): String = toolbox.show(tpe.asInstanceOf[Type[Any]])
17+
}
18+
1619
implicit def UnitTag: Type[Unit] = new TaggedType[Unit]
1720
implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean]
1821
implicit def ByteTag: Type[Byte] = new TaggedType[Byte]

library/src/scala/quoted/Expr.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ sealed abstract class Expr[+T] {
1010
*/
1111
final def run(implicit toolbox: Toolbox): T = toolbox.run(this)
1212

13-
/** Show a source code like representation of this expression */
14-
final def show(implicit toolbox: Toolbox): String = toolbox.show(this)
15-
1613
}
1714

1815
object Expr {
1916

2017
// TODO simplify using new extension methods
2118

19+
implicit class ExprOps[T](expr: Expr[T]) {
20+
/** Show a source code like representation of this expression */
21+
def show(implicit toolbox: Toolbox): String = toolbox.show(expr)
22+
}
23+
2224
implicit class AsFunction0[R](private val f: Expr[() => R]) extends AnyVal {
2325
def apply(): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array.empty)
2426
}

tests/run-with-compiler/quote-unrolled-foreach.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object Test {
2929
println(code4.show)
3030
println()
3131

32-
val liftedArray = Array(1, 2, 3, 4)
32+
val liftedArray: Expr[Array[Int]] = Array(1, 2, 3, 4)
3333
println(liftedArray.show)
3434
println()
3535

0 commit comments

Comments
 (0)