Skip to content

Commit 67fc1de

Browse files
committed
Replace seal implementation seal
Use `asExprOf[T]` when needed.
1 parent 0a9404a commit 67fc1de

File tree

17 files changed

+38
-43
lines changed

17 files changed

+38
-43
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/QuotedOpsImpl.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ trait QuotedOpsImpl extends scala.tasty.reflect.QuotedOps with CoreImpl {
3939
}
4040

4141
def TermToQuoteDeco(term: Term): TermToQuotedAPI = new TermToQuotedAPI {
42-
43-
def seal[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T] =
44-
QuotedExprDeco(seal2).asExprOf[T]
45-
46-
def seal2(implicit ctx: Context): scala.quoted.Expr[Tpe] = {
42+
def seal(implicit ctx: Context): scala.quoted.Expr[Tpe] = {
4743
def etaExpand(term: Term): Term = term.tpe.widen match {
4844
case mtpe: Types.MethodType if !mtpe.isParamDependent =>
4945
val closureResType = mtpe.resType match {

library/src-bootstrapped/scala/tasty/reflect/utils/TreeUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ trait TreeUtils {
99
import reflect._
1010

1111
def let(rhs: Term)(in: Term.Ident => Term): Term = {
12-
val rhsExpr = rhs.seal2
12+
val rhsExpr = rhs.seal
1313
val rhsTpe = rhsExpr.tpe
1414
val expr = '{
1515
val x: ~rhsTpe = ~rhsExpr
16-
~in(('(x)).unseal.asInstanceOf[Term.Ident]).seal2
16+
~in(('(x)).unseal.asInstanceOf[Term.Ident]).seal
1717
}
1818
expr.unseal
1919
}

library/src/scala/tasty/reflect/QuotedOps.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ trait QuotedOps extends Core {
2020
/** View this expression `Expr[T]` as a `Term` */
2121
def unseal(implicit ctx: Context): Term
2222

23-
/** Convert any `Expr[_]` to an `Expr[T]` and check that it conforms to `T` */
23+
/** Cast this `Expr` to an `Expr[T]`.
24+
*
25+
* Throws if this expression does not conform to `T`.
26+
*/
2427
def asExprOf[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T]
2528

2629
/** Get the quoted.Type of this expression */
@@ -37,14 +40,11 @@ trait QuotedOps extends Core {
3740
implicit def QuotedTypeDeco[T](tpe: quoted.Type[T]): QuotedTypeAPI
3841

3942
trait TermToQuotedAPI {
40-
/** Convert `Term` to an `Expr[T]` and check that it conforms to `T` */
41-
def seal[T: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[T]
42-
4343
/** Type of this expression */
4444
type Tpe
4545

4646
/** Convert `Term` to an `Expr[Tpe]` */
47-
def seal2(implicit ctx: Context): scala.quoted.Expr[Tpe]
47+
def seal(implicit ctx: Context): scala.quoted.Expr[Tpe]
4848
}
4949
implicit def TermToQuoteDeco(term: Term): TermToQuotedAPI
5050

tests/neg/tasty-macro-assert/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object Asserts {
3434

3535
tree match {
3636
case Term.Inlined(_, Nil, Term.Apply(Term.Select(OpsTree(left), op), right :: Nil)) =>
37-
'(assertTrue(~left.seal[Boolean])) // Buggy code. To generate the errors
37+
'(assertTrue(~left.seal.asExprOf[Boolean])) // Buggy code. To generate the errors
3838
case _ =>
3939
'(assertTrue(~cond))
4040
}

tests/run-with-compiler/tasty-unsafe-let/quoted_1.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@ object Macros {
77
inline def let[T](rhs: T)(body: => T => Unit): Unit =
88
~impl('(rhs), '(body))
99

10-
private def impl[T](rhs: Expr[T], body: Expr[T => Unit])(implicit reflect: Reflection): Expr[Unit] = {
10+
private def impl[T: Type](rhs: Expr[T], body: Expr[T => Unit])(implicit reflect: Reflection): Expr[Unit] = {
1111
import reflect._
1212

1313
val rhsTerm = rhs.unseal
1414

1515
import reflect.util.{let => letTerm}
1616
letTerm(rhsTerm) { rhsId =>
17-
body(rhsId.seal[Any].asInstanceOf[Expr[T]]).unseal // Dangerous uncheked cast!
18-
}.seal[Unit]
17+
body(rhsId.seal.asExprOf[T]).unseal
18+
}.seal.asExprOf[Unit]
1919
}
2020

21-
2221
}

tests/run/f-interpolation-1/FQuote_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object FQuote {
1414

1515
def liftListOfAny(lst: List[Term]): Expr[List[Any]] = lst match {
1616
case x :: xs =>
17-
val head = x.seal[Any]
17+
val head: Expr[Any] = x.seal
1818
val tail = liftListOfAny(xs)
1919
'{ ~head :: ~tail }
2020
case Nil => '(Nil)

tests/run/i5533/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object scalatest {
1313

1414
val tree = condition.unseal
1515

16-
val expr = tree.seal[Boolean]
16+
val expr = tree.seal.asExprOf[Boolean]
1717

1818
'(println(~expr))
1919
}

tests/run/i5533b/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ object scalatest {
1616

1717
tree.underlyingArgument match {
1818
case Term.Apply(Term.Select(lhs, op), rhs :: Nil) =>
19-
val left = lhs.seal[Any]
20-
val right = rhs.seal[Any]
19+
val left: Expr[Any] = lhs.seal
20+
val right: Expr[Any] = rhs.seal
2121
op match {
2222
case "==" =>
2323
'{

tests/run/i5536/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ object scalatest {
1313

1414
tree.underlyingArgument match {
1515
case Term.Apply(Term.Select(lhs, op), rhs :: Nil) =>
16-
val left = lhs.seal[Any]
17-
val right = rhs.seal[Any]
16+
val left: Expr[Any] = lhs.seal
17+
val right: Expr[Any] = rhs.seal
1818
op match {
1919
case "===" =>
2020
'{

tests/run/reflect-select-copy/assert_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object scalatest {
1212
cond.unseal.underlyingArgument match {
1313
case Term.Apply(sel @ Term.Select(lhs, op), rhs :: Nil) =>
1414
val Term.IsSelect(select) = sel
15-
val cond = Term.Apply(Term.Select.copy(select)(lhs, ">"), rhs :: Nil).seal[Boolean]
15+
val cond = Term.Apply(Term.Select.copy(select)(lhs, ">"), rhs :: Nil).seal.asExprOf[Boolean]
1616
'{ scala.Predef.assert(~cond) }
1717
case _ =>
1818
'{ scala.Predef.assert(~cond) }

0 commit comments

Comments
 (0)