Skip to content

Commit 1beb55f

Browse files
authored
Merge pull request #6867 from dotty-staging/cleanup-quoted-expr-and-type-api
Cleanup `quoted.{Expr|Type}` APIs
2 parents 1870b14 + 1de97dc commit 1beb55f

File tree

4 files changed

+35
-43
lines changed

4 files changed

+35
-43
lines changed

library/src/scala/quoted/Expr.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package quoted {
44

55
import scala.quoted.show.SyntaxHighlight
66

7-
sealed abstract class Expr[+T] {
7+
sealed trait Expr[+T] {
88

99
/** Evaluate the contents of this expression and return the result.
1010
*
@@ -13,22 +13,18 @@ package quoted {
1313
@deprecated("Use scala.quoted.run", "")
1414
final def run(implicit toolbox: Toolbox): T = toolbox.run(_ => this)
1515

16+
/** Show a source code like representation of this expression without syntax highlight */
17+
def show(implicit qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain)
18+
19+
/** Show a source code like representation of this expression */
20+
def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(this, syntaxHighlight)
21+
1622
}
1723

1824
object Expr {
1925

2026
import scala.internal.quoted._
2127

22-
implicit class ExprOps[T](expr: Expr[T]) {
23-
24-
/** Show a source code like representation of this expression without syntax highlight */
25-
def show(implicit qctx: QuoteContext): String = qctx.show(expr, SyntaxHighlight.plain)
26-
27-
/** Show a source code like representation of this expression */
28-
def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(expr, syntaxHighlight)
29-
30-
}
31-
3228
/** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */
3329
type TupleOfExpr[Tup <: Tuple] = Tuple.Map[Tup, Expr]
3430

library/src/scala/quoted/Liftable.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ trait Liftable[T] {
1717
*/
1818
object Liftable {
1919

20-
implicit val Liftable_Boolean_delegate: Liftable[Boolean] = new PrimitiveLiftable
21-
implicit val Liftable_Byte_delegate: Liftable[Byte] = new PrimitiveLiftable
22-
implicit val Liftable_Short_delegate: Liftable[Short] = new PrimitiveLiftable
23-
implicit val Liftable_Int_delegate: Liftable[Int] = new PrimitiveLiftable
24-
implicit val Liftable_Long_delegate: Liftable[Long] = new PrimitiveLiftable
25-
implicit val Liftable_Float_delegate: Liftable[Float] = new PrimitiveLiftable
26-
implicit val Liftable_Double_delegate: Liftable[Double] = new PrimitiveLiftable
27-
implicit val Liftable_Char_delegate: Liftable[Char] = new PrimitiveLiftable
28-
implicit val Liftable_String_delegate: Liftable[String] = new PrimitiveLiftable
20+
delegate Liftable_Boolean_delegate for Liftable[Boolean] = new PrimitiveLiftable
21+
delegate Liftable_Byte_delegate for Liftable[Byte] = new PrimitiveLiftable
22+
delegate Liftable_Short_delegate for Liftable[Short] = new PrimitiveLiftable
23+
delegate Liftable_Int_delegate for Liftable[Int] = new PrimitiveLiftable
24+
delegate Liftable_Long_delegate for Liftable[Long] = new PrimitiveLiftable
25+
delegate Liftable_Float_delegate for Liftable[Float] = new PrimitiveLiftable
26+
delegate Liftable_Double_delegate for Liftable[Double] = new PrimitiveLiftable
27+
delegate Liftable_Char_delegate for Liftable[Char] = new PrimitiveLiftable
28+
delegate Liftable_String_delegate for Liftable[String] = new PrimitiveLiftable
2929

3030
private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] {
3131
/** Lift a primitive value `n` into `'{ n }` */

library/src/scala/quoted/QuoteContext.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import scala.quoted.show.SyntaxHighlight
1212
*/
1313
class QuoteContext(val tasty: scala.tasty.Reflection) {
1414

15-
def show[T](expr: Expr[T], syntaxHighlight: SyntaxHighlight): String = {
15+
def show(expr: Expr[_], syntaxHighlight: SyntaxHighlight): String = {
1616
import tasty._
1717
expr.unseal.show(syntaxHighlight)
1818
}
1919

20-
def show[T](tpe: Type[T], syntaxHighlight: SyntaxHighlight): String = {
20+
def show(tpe: Type[_], syntaxHighlight: SyntaxHighlight): String = {
2121
import tasty._
2222
tpe.unseal.show(syntaxHighlight)
2323
}

library/src/scala/quoted/Type.scala

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,28 @@ package quoted {
44
import scala.internal.quoted.TaggedType
55
import scala.quoted.show.SyntaxHighlight
66

7-
sealed abstract class Type[T <: AnyKind] {
7+
sealed trait Type[T <: AnyKind] {
88
type `$splice` = T
9-
}
10-
11-
/** Some basic type tags, currently incomplete */
12-
object Type {
13-
14-
implicit class TypeOps[T](tpe: Type[T]) {
159

16-
/** Show a source code like representation of this type without syntax highlight */
17-
def show(implicit qctx: QuoteContext): String = qctx.show(tpe, SyntaxHighlight.plain)
10+
/** Show a source code like representation of this type without syntax highlight */
11+
def show(implicit qctx: QuoteContext): String = qctx.show(this, SyntaxHighlight.plain)
1812

19-
/** Show a source code like representation of this type */
20-
def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(tpe, syntaxHighlight)
13+
/** Show a source code like representation of this type */
14+
def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(this, syntaxHighlight)
2115

22-
}
16+
}
2317

24-
implicit val UnitTag: Type[Unit] = new TaggedType[Unit]
25-
implicit val BooleanTag: Type[Boolean] = new TaggedType[Boolean]
26-
implicit val ByteTag: Type[Byte] = new TaggedType[Byte]
27-
implicit val CharTag: Type[Char] = new TaggedType[Char]
28-
implicit val ShortTag: Type[Short] = new TaggedType[Short]
29-
implicit val IntTag: Type[Int] = new TaggedType[Int]
30-
implicit val LongTag: Type[Long] = new TaggedType[Long]
31-
implicit val FloatTag: Type[Float] = new TaggedType[Float]
32-
implicit val DoubleTag: Type[Double] = new TaggedType[Double]
18+
/** Some basic type tags, currently incomplete */
19+
object Type {
20+
delegate UnitTag for Type[Unit] = new TaggedType[Unit]
21+
delegate BooleanTag for Type[Boolean] = new TaggedType[Boolean]
22+
delegate ByteTag for Type[Byte] = new TaggedType[Byte]
23+
delegate CharTag for Type[Char] = new TaggedType[Char]
24+
delegate ShortTag for Type[Short] = new TaggedType[Short]
25+
delegate IntTag for Type[Int] = new TaggedType[Int]
26+
delegate LongTag for Type[Long] = new TaggedType[Long]
27+
delegate FloatTag for Type[Float] = new TaggedType[Float]
28+
delegate DoubleTag for Type[Double] = new TaggedType[Double]
3329
}
3430

3531
}

0 commit comments

Comments
 (0)