Skip to content

Commit cff4a78

Browse files
committed
Replace seal implementation seal
Use `asExprOf[T]` when needed.
1 parent 52e3cb2 commit cff4a78

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) }

tests/run/tasty-interpolation-1/Macro.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ abstract class MacroStringInterpolator[T] {
5959
case Term.Select(Term.Typed(Term.Apply(_, List(Term.Apply(_, List(Term.Typed(Term.Repeated(strCtxArgTrees, _), TypeTree.Inferred()))))), _), _) =>
6060
val strCtxArgs = strCtxArgTrees.map {
6161
case Term.Literal(Constant.String(str)) => str
62-
case tree => throw new NotStaticlyKnownError("Expected statically known StringContext", tree.seal[Any])
62+
case tree => throw new NotStaticlyKnownError("Expected statically known StringContext", tree.seal)
6363
}
6464
StringContext(strCtxArgs: _*)
6565
case tree =>
66-
throw new NotStaticlyKnownError("Expected statically known StringContext", tree.seal[Any])
66+
throw new NotStaticlyKnownError("Expected statically known StringContext", tree.seal)
6767
}
6868
}
6969

7070
protected def getArgsList(argsExpr: Expr[Seq[Any]])(implicit reflect: Reflection): List[Expr[Any]] = {
7171
import reflect._
7272
argsExpr.unseal.underlyingArgument match {
73-
case Term.Typed(Term.Repeated(args, _), _) => args.map(_.seal[Any])
74-
case tree => throw new NotStaticlyKnownError("Expected statically known argument list", tree.seal[Any])
73+
case Term.Typed(Term.Repeated(args, _), _) => args.map(_.seal)
74+
case tree => throw new NotStaticlyKnownError("Expected statically known argument list", tree.seal)
7575
}
7676
}
7777

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ object Asserts {
3535
tree match {
3636
case Term.Inlined(_, Nil, Term.Apply(Term.Select(OpsTree(left), op), right :: Nil)) =>
3737
op match {
38-
case "===" => '(assertEquals(~left.seal[Any], ~right.seal[Any]))
39-
case "!==" => '(assertNotEquals(~left.seal[Any], ~right.seal[Any]))
38+
case "===" => '(assertEquals[Any](~left.seal, ~right.seal))
39+
case "!==" => '(assertNotEquals[Any](~left.seal, ~right.seal))
4040
}
4141
case _ =>
4242
'(assertTrue(~cond))

tests/run/tasty-macro-const/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Macros {
1212
case Term.Literal(Constant.Int(n)) =>
1313
if (n <= 0)
1414
throw new QuoteError("Parameter must be natural number")
15-
xTree.seal[Int]
15+
xTree.seal.asExprOf[Int]
1616
case _ =>
1717
throw new QuoteError("Parameter must be a known constant")
1818
}

tests/run/tasty-seal-method/quoted_1.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ object Asserts {
1616
fn.tpe.widen match {
1717
case Type.IsMethodType(_) =>
1818
args.size match {
19-
case 0 => fn.seal[() => Int].apply()
20-
case 1 => fn.seal[Int => Int].apply('(0))
21-
case 2 => fn.seal[(Int, Int) => Int].apply('(0), '(0))
22-
case 3 => fn.seal[(Int, Int, Int) => Int].apply('(0), '(0), '(0))
19+
case 0 => fn.seal.asExprOf[() => Int].apply()
20+
case 1 => fn.seal.asExprOf[Int => Int].apply('(0))
21+
case 2 => fn.seal.asExprOf[(Int, Int) => Int].apply('(0), '(0))
22+
case 3 => fn.seal.asExprOf[(Int, Int, Int) => Int].apply('(0), '(0), '(0))
2323
}
2424
}
2525
case _ => x
@@ -37,15 +37,15 @@ object Asserts {
3737
case Term.Apply(fn, args) =>
3838
val pre = rec(fn)
3939
args.size match {
40-
case 0 => pre.seal[() => Any].apply().unseal
41-
case 1 => pre.seal[Int => Any].apply('(0)).unseal
42-
case 2 => pre.seal[(Int, Int) => Any].apply('(0), '(0)).unseal
43-
case 3 => pre.seal[(Int, Int, Int) => Any].apply('(0), '(0), '(0)).unseal
40+
case 0 => pre.seal.asExprOf[() => Any].apply().unseal
41+
case 1 => pre.seal.asExprOf[Int => Any].apply('(0)).unseal
42+
case 2 => pre.seal.asExprOf[(Int, Int) => Any].apply('(0), '(0)).unseal
43+
case 3 => pre.seal.asExprOf[(Int, Int, Int) => Any].apply('(0), '(0), '(0)).unseal
4444
}
4545
case _ => term
4646
}
4747

48-
rec(x.unseal.underlyingArgument).seal[Int]
48+
rec(x.unseal.underlyingArgument).seal.asExprOf[Int]
4949
}
5050

5151
}

tests/run/tasty-tree-map/quoted_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Macros {
88
def impl[T: Type](x: Expr[T])(implicit reflection: Reflection): Expr[T] = {
99
import reflection._
1010
val identityMap = new TreeMap { }
11-
val transformed = identityMap.transformTerm(x.unseal).seal[T]
11+
val transformed = identityMap.transformTerm(x.unseal).seal.asExprOf[T]
1212
transformed
1313
}
1414

tests/run/xml-interpolation-1/XmlQuote_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object XmlQuote {
2727

2828
def liftListOfAny(lst: List[Term]): Expr[List[Any]] = lst match {
2929
case x :: xs =>
30-
val head = x.seal[Any]
30+
val head: Expr[Any] = x.seal
3131
val tail = liftListOfAny(xs)
3232
'{ ~head :: ~tail }
3333
case Nil => '(Nil)

tests/run/xml-interpolation-2/XmlQuote_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object XmlQuote {
5656
// [a0, ...]: Any*
5757
val args2: Expr[List[Any]] = args.unseal.underlyingArgument match {
5858
case Typed(Repeated(args0, _), _) => // statically known args, make list directly
59-
args0.map(_.seal[Any]).toExprOfList
59+
args0.map(_.seal.asExprOf[Any]).toExprOfList
6060
case _ =>
6161
'((~args).toList)
6262

0 commit comments

Comments
 (0)