Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions library/src-bootstrapped/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ abstract class Expr[+T] private[scala] {
val ExprMatch = qctx.asInstanceOf[scala.internal.quoted.QuoteContextInternal].ExprMatch
ExprMatch.unapply[EmptyTuple, EmptyTuple](this)(using that).nonEmpty

/** Checked cast to a `quoted.Expr[U]` */
def cast[U](using tp: scala.quoted.Type[U])(using qctx: QuoteContext): scala.quoted.Expr[U] = asExprOf[U]

/** Checks is the `quoted.Expr[?]` is valid expression of type `X` */
def isExprOf[X](using tp: scala.quoted.Type[X])(using qctx: QuoteContext): Boolean =
this.unseal.tpe <:< qctx.reflect.TypeRepr.of[X]
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/tasty-macro-assert-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Asserts {

tree match {
case Inlined(_, Nil, Apply(Select(OpsTree(left), op), right :: Nil)) =>
'{assertTrue(${left.seal.cast[Boolean]})} // Buggy code. To generate the errors
'{assertTrue(${left.asExprOf[Boolean]})} // Buggy code. To generate the errors
case _ =>
'{assertTrue($cond)}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/tasty-macro-assert-2/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object Asserts {

tree match {
case Inlined(_, Nil, Apply(Select(OpsTree(left), op), right :: Nil)) =>
'{assertTrue(${left.seal.cast[Boolean]})} // Buggy code. To generate the errors
'{assertTrue(${left.asExprOf[Boolean]})} // Buggy code. To generate the errors
case _ =>
'{assertTrue($cond)}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-staging/i5941/macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Lens {
import util._
// obj.copy(field = value)
def setterBody(obj: Expr[S], value: Expr[T], field: String): Expr[S] =
Select.overloaded(obj.unseal, "copy", Nil, NamedArg(field, value.unseal) :: Nil, TypeBounds.empty).seal.cast[S]
Select.overloaded(obj.unseal, "copy", Nil, NamedArg(field, value.unseal) :: Nil, TypeBounds.empty).asExprOf[S]

// exception: getter.unseal.underlyingArgument
getter.unseal match {
Expand Down
4 changes: 2 additions & 2 deletions tests/pos-macros/i6535/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ object scalatest {
let(app) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i7887.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ def typed[A](using t: quoted.Type[A], qctx: quoted.QuoteContext): Unit = {
import qctx.reflect._
'{
type T = A
${'{???}.cast[T]}
${'{???}.asExprOf[T]}
}
}
2 changes: 1 addition & 1 deletion tests/pos-macros/i8866/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object Macro {
'{ OtherMacro }.unseal,
"apply"
)
)(identity).seal.cast[Int]
)(identity).asExprOf[Int]
}

inline def apply = ${ Macro.impl }
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i8866b/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object Macro {
'{ Other }.unseal,
"apply"
)
)(identity).seal.cast[Int]
)(identity).asExprOf[Int]

}

Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i9687/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object X {
case _ => super.transformTerm(term)
}
}
val r = transformer.transformTerm(x.unseal).seal.cast[A]
val r = transformer.transformTerm(x.unseal).asExprOf[A]
s"result: ${r.show}"
r
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/i9894/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ object X:
}
changes.transformTerm(body)

transform(f.unseal).seal.cast[CB[T]]
transform(f.unseal).asExprOf[CB[T]]
2 changes: 1 addition & 1 deletion tests/pos-macros/treemap-unapply/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ def mcrImpl(x: Expr[Unit])(using QuoteContext) : Expr[Unit] =
import qctx.reflect._
val tr: Term = x.unseal
object m extends TreeMap
m.transformTerm(tr).seal.cast[Unit]
m.transformTerm(tr).asExprOf[Unit]
2 changes: 1 addition & 1 deletion tests/run-macros/i5533/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object scalatest {

val tree = condition.unseal

val expr = tree.seal.cast[Boolean]
val expr = tree.asExprOf[Boolean]

'{println($expr)}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i5629/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Macros {

def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(using qctx: QuoteContext) : Expr[Unit] = {
import qctx.reflect._
val b = cond.unseal.underlyingArgument.seal.cast[Boolean]
val b = cond.unseal.underlyingArgument.asExprOf[Boolean]
'{ scala.Predef.assert($b) }
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i5715/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object scalatest {

cond.unseal.underlyingArgument match {
case app @ Apply(select @ Select(lhs, op), rhs :: Nil) =>
val cond = Apply(Select.copy(select)(lhs, "exists"), rhs :: Nil).seal.cast[Boolean]
val cond = Apply(Select.copy(select)(lhs, "exists"), rhs :: Nil).asExprOf[Boolean]
'{ scala.Predef.assert($cond) }
case _ =>
'{ scala.Predef.assert($cond) }
Expand Down
10 changes: 5 additions & 5 deletions tests/run-macros/i5941/macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object Lens {
getter.unseal match {
case Function(param :: Nil, Path(o, parts)) if o.symbol == param.symbol =>
'{
val setter = (t: T) => (s: S) => ${ setterBody(('s).unseal, ('t).unseal, parts).seal.cast[S] }
val setter = (t: T) => (s: S) => ${ setterBody(('s).unseal, ('t).unseal, parts).asExprOf[S] }
apply($getter)(setter)
}
case _ =>
Expand Down Expand Up @@ -116,9 +116,9 @@ object Iso {
'{???}
} else '{
// (p: S) => p._1
val to = (p: S) => ${ Select.unique(('p).unseal, "_1").seal.cast[A] }
val to = (p: S) => ${ Select.unique(('p).unseal, "_1").asExprOf[A] }
// (p: A) => S(p)
val from = (p: A) => ${ Select.overloaded(Ident(companion), "apply", Nil, ('p).unseal :: Nil).seal.cast[S] }
val from = (p: A) => ${ Select.overloaded(Ident(companion), "apply", Nil, ('p).unseal :: Nil).asExprOf[S] }
apply(from)(to)
}
}
Expand All @@ -130,7 +130,7 @@ object Iso {
val tpS = TypeRepr.of[S]

if (tpS.isSingleton) {
val ident = Ident(tpS.asInstanceOf[TermRef]).seal.cast[S]
val ident = Ident(tpS.asInstanceOf[TermRef]).asExprOf[S]
'{
Iso[S, 1](Function.const($ident))(Function.const(1))
}
Expand All @@ -147,7 +147,7 @@ object Iso {
case TypeRef(prefix, name) => TermRef(prefix, name)
}

val obj = Select.overloaded(Ident(companion), "apply", Nil, Nil).seal.cast[S]
val obj = Select.overloaded(Ident(companion), "apply", Nil, Nil).asExprOf[S]

'{
Iso[S, 1](Function.const($obj))(Function.const(1))
Expand Down
8 changes: 4 additions & 4 deletions tests/run-macros/i6171/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ object scalatest {
ValDef.let(app) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
case Apply(f @ Apply(Select(Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits)
if isImplicitMethodType(f.tpe) =>
ValDef.let(lhs) { left =>
Expand All @@ -34,12 +34,12 @@ object scalatest {
ValDef.let(Apply(app, implicits)) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
}
}
}
2 changes: 1 addition & 1 deletion tests/run-macros/i7887/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def myMacroImpl(a: quoted.Expr[_])(using qctx: quoted.QuoteContext) = {
implicit val t: quoted.Type[A] = a.unseal.tpe.widen.seal.asInstanceOf[quoted.Type[A]]
'{
type T = A
${a.unseal.seal.cast[T]}
${a.unseal.asExprOf[T]}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/quote-toExprOfTuple/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ object Macro {

val seq = List(t0, t1)
val res = Expr.ofTupleFromSeq(seq)
res.cast[(T0, T1)]
res.asExprOf[(T0, T1)]
}
}
8 changes: 4 additions & 4 deletions tests/run-macros/reflect-dsl/assert_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ object scalatest {
ValDef.let(app) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
case Apply(f @ Apply(sel @ Select(Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits)
if isImplicitMethodType(f.tpe) =>
ValDef.let(lhs) { left =>
Expand All @@ -34,12 +34,12 @@ object scalatest {
ValDef.let(Apply(app, implicits)) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/reflect-pos-fun/assert_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ object scalatest {
ValDef.let(lhs) { left =>
ValDef.let(rhs) { rs =>
val app = Select.overloaded(left, op, targs.map(_.tpe), rs)
val b = app.seal.cast[Boolean]
val b = app.asExprOf[Boolean]
'{ scala.Predef.assert($b) }.unseal
}
}.seal.cast[Unit]
}.asExprOf[Unit]
}
}
}
8 changes: 4 additions & 4 deletions tests/run-macros/reflect-select-constructor/assert_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ object scalatest {
ValDef.let(app) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
case Apply(f @ Apply(Select(Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits)
if isImplicitMethodType(f.tpe) =>
ValDef.let(lhs) { left =>
Expand All @@ -34,12 +34,12 @@ object scalatest {
ValDef.let(Apply(app, implicits)) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/run-macros/reflect-select-copy-2/assert_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ object scalatest {
ValDef.let(Apply(Select.copy(sel)(left, op), right :: Nil)) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert(${b}) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
case Apply(f @ Apply(sel @ Select(Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits)
if isImplicitMethodType(f.tpe) =>
ValDef.let(lhs) { left =>
ValDef.let(rhs) { right =>
ValDef.let(Apply(Apply(Select.copy(sel)(Apply(qual, left :: Nil), op), right :: Nil), implicits)) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert(${b}) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/reflect-select-copy/assert_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object scalatest {

cond.unseal.underlyingArgument match {
case Apply(select @ Select(lhs, op), rhs :: Nil) =>
val cond = Apply(Select.copy(select)(lhs, ">"), rhs :: Nil).seal.cast[Boolean]
val cond = Apply(Select.copy(select)(lhs, ">"), rhs :: Nil).asExprOf[Boolean]
'{ scala.Predef.assert($cond) }
case _ =>
'{ scala.Predef.assert($cond) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ object scalatest {
ValDef.let(app) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
case Apply(f @ Apply(sel @ Select(Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits)
if isImplicitMethodType(f.tpe) =>
ValDef.let(lhs) { left =>
Expand All @@ -34,12 +34,12 @@ object scalatest {
ValDef.let(Apply(app, implicits)) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/run-macros/reflect-select-value-class/assert_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ object scalatest {
ValDef.let(app) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
case Apply(f @ Apply(Select(Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits)
if isImplicitMethodType(f.tpe) =>
ValDef.let(lhs) { left =>
Expand All @@ -34,12 +34,12 @@ object scalatest {
ValDef.let(Apply(app, implicits)) { result =>
val l = left.seal
val r = right.seal
val b = result.seal.cast[Boolean]
val b = result.asExprOf[Boolean]
val code = '{ scala.Predef.assert($b) }
code.unseal
}
}
}.seal.cast[Unit]
}.asExprOf[Unit]
}
}

Expand Down
Loading