Skip to content

Commit 425b0f0

Browse files
committed
Improve Quoted.toString implementations
Avoid leaking internal representation to the user
1 parent 84313fb commit 425b0f0

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

library/src/scala/quoted/Liftable.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ abstract class Liftable[T] {
1414
*/
1515
object Liftable {
1616

17-
final class ConstantExpr[T] private[Liftable](val value: T) extends Expr[T]
17+
final class ConstantExpr[T] private[Liftable](val value: T) extends Expr[T] {
18+
override def toString: String = s"Expr($value)"
19+
}
1820

1921
implicit def BooleanIsLiftable: Liftable[Boolean] = (x: Boolean) => new ConstantExpr(x)
2022
implicit def ByteLiftable: Liftable[Byte] = (x: Byte) => new ConstantExpr(x)

library/src/scala/quoted/TastyExpr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import scala.runtime.quoted.Unpickler.Pickled
44

55
/** An Expr backed by a pickled TASTY tree */
66
final case class TastyExpr[T](tasty: Pickled, args: Seq[Any]) extends Expr[T] with TastyQuoted {
7-
override def toString(): String = s"TastyExpr(<TASTY>, $args)"
7+
override def toString(): String = s"Expr(<pickled>)"
88
}

library/src/scala/quoted/TastyType.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import scala.runtime.quoted.Unpickler.Pickled
44

55
/** A Type backed by a pickled TASTY tree */
66
final case class TastyType[T](tasty: Pickled, args: Seq[Any]) extends Type[T] with TastyQuoted {
7-
override def toString(): String = s"TastyType(<TASTY>, $args)"
7+
override def toString(): String = s"Type(<pickled>)"
88
}

library/src/scala/quoted/Type.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ abstract class Type[T] extends Quoted {
99
/** Some basic type tags, currently incomplete */
1010
object Type {
1111

12-
class TaggedPrimitive[T] private[Type] (implicit val ct: ClassTag[T]) extends Type[T]
12+
class TaggedPrimitive[T] private[Type] (implicit val ct: ClassTag[T]) extends Type[T] {
13+
override def toString: String = s"Type($ct)"
14+
}
1315

1416
implicit def UnitTag: Type[Unit] = new TaggedPrimitive[Unit]
1517
implicit def BooleanTag: Type[Boolean] = new TaggedPrimitive[Boolean]

0 commit comments

Comments
 (0)