Skip to content

Commit 5250033

Browse files
committed
Use QuoteScope in some methods
1 parent 990aaeb commit 5250033

File tree

6 files changed

+35
-30
lines changed

6 files changed

+35
-30
lines changed

library/src-bootstrapped/scala/quoted/Expr.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Expr[+T] private[scala] {
4545
qctx.tasty.internal.QuotedExpr_cast[U](this)(using tp, qctx.tasty.rootContext)
4646

4747
/** View this expression `quoted.Expr[T]` as a `Term` */
48-
def unseal(using qctx: QuoteContext): qctx.tasty.Term =
48+
def unseal(using qctx: QuoteScope): qctx.tasty.Term =
4949
qctx.tasty.internal.QuotedExpr_unseal(this)(using qctx.tasty.rootContext)
5050

5151
}
@@ -78,15 +78,15 @@ object Expr {
7878
tg.untupled(args => qctx.tasty.internal.betaReduce(f.unseal, args.toArray.toList.map(_.asInstanceOf[QuoteContext => Expr[Any]](qctx).unseal)).seal.asInstanceOf[Expr[R]])
7979

8080
/** Returns a null expresssion equivalent to `'{null}` */
81-
def nullExpr: QuoteContext ?=> Expr[Null] = qctx ?=> {
81+
def nullExpr: (s: QuoteScope) ?=> s.Expr[Null] = {
8282
import qctx.tasty._
83-
Literal(Constant(null)).seal.asInstanceOf[Expr[Null]]
83+
Literal(Constant(null)).seal.asInstanceOf[qctx.Expr[Null]]
8484
}
8585

8686
/** Returns a unit expresssion equivalent to `'{}` or `'{()}` */
87-
def unitExpr: QuoteContext ?=> Expr[Unit] = qctx ?=> {
87+
def unitExpr: (s: QuoteScope) ?=> s.Expr[Unit] = {
8888
import qctx.tasty._
89-
Literal(Constant(())).seal.asInstanceOf[Expr[Unit]]
89+
Literal(Constant(())).seal.asInstanceOf[qctx.Expr[Unit]]
9090
}
9191

9292
/** Returns an expression containing a block with the given statements and ending with the expresion

library/src-bootstrapped/scala/quoted/QuoteContext.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ trait QuoteContext extends QuoteScope { self =>
2626
}
2727

2828
object QuoteContext {
29+
30+
given unsafeQuoteContext as Conversion[QuoteScope, QuoteContext] = _.asInstanceOf
31+
2932
// TODO remove in 0.26.0
3033
@deprecated("Errors and warnings have been moved to scala.quoted.Reporting", "0.25.0")
3134
given error_and_warining_on_QuoteContext as Conversion[QuoteContext, Reporting.type] = _ => Reporting

library/src-bootstrapped/scala/quoted/Reporting.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@ package scala.quoted
33
object Reporting {
44

55
/** Report an error at the position of the macro expansion */
6-
def error(msg: => String)(using qctx: QuoteContext): Unit =
6+
def error(msg: => String)(using QuoteScope): Unit =
77
qctx.tasty.error(msg, qctx.tasty.rootPosition)
88

99
/** Report an error at the on the position of `expr` */
10-
def error(msg: => String, expr: Expr[Any])(using qctx: QuoteContext): Unit =
10+
def error(msg: => String, expr: Expr[Any])(using QuoteScope): Unit =
1111
qctx.tasty.error(msg, expr.unseal.pos)
1212

1313
/** Report an error at the position of the macro expansion and throws a StopQuotedContext */
14-
def throwError(msg: => String)(using qctx: QuoteContext): Nothing = {
14+
def throwError(msg: => String)(using QuoteScope): Nothing = {
1515
error(msg)
1616
throw new StopQuotedContext
1717
}
1818
/** Report an error at the on the position of `expr` and throws a StopQuotedContext */
19-
def throwError(msg: => String, expr: Expr[Any])(using qctx: QuoteContext): Nothing = {
19+
def throwError(msg: => String, expr: Expr[Any])(using QuoteScope): Nothing = {
2020
error(msg, expr)
2121
throw new StopQuotedContext
2222
}
2323

2424
/** Report a warning */
25-
def warning(msg: => String)(using qctx: QuoteContext): Unit =
25+
def warning(msg: => String)(using qctx: QuoteScope): Unit =
2626
qctx.tasty.warning(msg, qctx.tasty.rootPosition)
2727

2828
/** Report a warning at the on the position of `expr` */
29-
def warning(msg: => String, expr: Expr[_])(using qctx: QuoteContext): Unit =
29+
def warning(msg: => String, expr: Expr[_])(using QuoteScope): Unit =
3030
qctx.tasty.warning(msg, expr.unseal.pos)
3131

3232
/** Throwable used to stop the expansion of a macro after an error was reported */
33+
// TODO rename to StopQuotedScope
3334
class StopQuotedContext extends Throwable
3435

3536
}

library/src-bootstrapped/scala/quoted/Type.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ class Type[T <: AnyKind] private[scala] {
2323
/** Some basic type tags, currently incomplete */
2424
object Type {
2525

26-
def UnitTag: QuoteContext ?=> Type[Unit] =
27-
qctx.tasty.defn.UnitType.seal.asInstanceOf[quoted.Type[Unit]]
26+
def UnitTag: (s: QuoteScope) ?=> s.Type[Unit] =
27+
qctx.tasty.defn.UnitType.seal.asInstanceOf[qctx.Type[Unit]]
2828

29-
def BooleanTag: QuoteContext ?=> Type[Boolean] =
30-
qctx.tasty.defn.BooleanType.seal.asInstanceOf[quoted.Type[Boolean]]
29+
def BooleanTag: (s: QuoteScope) ?=> s.Type[Boolean] =
30+
qctx.tasty.defn.BooleanType.seal.asInstanceOf[qctx.Type[Boolean]]
3131

32-
def ByteTag: QuoteContext ?=> Type[Byte] =
33-
qctx.tasty.defn.ByteType.seal.asInstanceOf[quoted.Type[Byte]]
32+
def ByteTag: (s: QuoteScope) ?=> s.Type[Byte] =
33+
qctx.tasty.defn.ByteType.seal.asInstanceOf[qctx.Type[Byte]]
3434

35-
def CharTag: QuoteContext ?=> Type[Char] =
36-
qctx.tasty.defn.CharType.seal.asInstanceOf[quoted.Type[Char]]
35+
def CharTag: (s: QuoteScope) ?=> s.Type[Char] =
36+
qctx.tasty.defn.CharType.seal.asInstanceOf[qctx.Type[Char]]
3737

38-
def ShortTag: QuoteContext ?=> Type[Short] =
39-
qctx.tasty.defn.ShortType.seal.asInstanceOf[quoted.Type[Short]]
38+
def ShortTag: (s: QuoteScope) ?=> s.Type[Short] =
39+
qctx.tasty.defn.ShortType.seal.asInstanceOf[qctx.Type[Short]]
4040

41-
def IntTag: QuoteContext ?=> Type[Int] =
42-
qctx.tasty.defn.IntType.seal.asInstanceOf[quoted.Type[Int]]
41+
def IntTag: (s: QuoteScope) ?=> s.Type[Int] =
42+
qctx.tasty.defn.IntType.seal.asInstanceOf[qctx.Type[Int]]
4343

44-
def LongTag: QuoteContext ?=> Type[Long] =
45-
qctx.tasty.defn.LongType.seal.asInstanceOf[quoted.Type[Long]]
44+
def LongTag: (s: QuoteScope) ?=> s.Type[Long] =
45+
qctx.tasty.defn.LongType.seal.asInstanceOf[qctx.Type[Long]]
4646

47-
def FloatTag: QuoteContext ?=> Type[Float] =
48-
qctx.tasty.defn.FloatType.seal.asInstanceOf[quoted.Type[Float]]
47+
def FloatTag: (s: QuoteScope) ?=> s.Type[Float] =
48+
qctx.tasty.defn.FloatType.seal.asInstanceOf[qctx.Type[Float]]
4949

50-
def DoubleTag: QuoteContext ?=> Type[Double] =
51-
qctx.tasty.defn.DoubleType.seal.asInstanceOf[quoted.Type[Double]]
50+
def DoubleTag: (s: QuoteScope) ?=> s.Type[Double] =
51+
qctx.tasty.defn.DoubleType.seal.asInstanceOf[qctx.Type[Double]]
5252

5353
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package scala.quoted
22

33
/** Current QuoteContext in scope */
4-
def qctx(using qctx: QuoteContext): qctx.type = qctx
4+
def qctx(using s: QuoteScope): s.type = s

library/src-non-bootstrapped/scala/quoted/Reporting.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package scala.quoted
33
object Reporting {
44

55
/** Throwable used to stop the expansion of a macro after an error was reported */
6+
// TODO rename to StopQuotedScope
67
class StopQuotedContext extends Throwable
78

89
}

0 commit comments

Comments
 (0)