@@ -2109,6 +2109,20 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
2109
2109
def newMethod (parent : Symbol , name : String , tpe : Type , flags : Flags , privateWithin : Symbol )(using ctx : Context ): Symbol =
2110
2110
internal.Symbol_newMethod (parent, name, flags, tpe, privateWithin)
2111
2111
2112
+ /** Generates a new val/var/lazy val symbol with the given parent, name and type.
2113
+ *
2114
+ * This symbol starts without an accompanying definition.
2115
+ * It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing
2116
+ * this symbol to the ValDef constructor.
2117
+ *
2118
+ * @param flags extra flags to with which the symbol should be constructed
2119
+ * @param privateWithin the symbol within which this new method symbol should be private. May be noSymbol.
2120
+ * @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be
2121
+ * direct or indirect children of the reflection context's owner.
2122
+ */
2123
+ def newVal (parent : Symbol , name : String , tpe : Type , flags : Flags , privateWithin : Symbol )(using ctx : Context ): Symbol =
2124
+ internal.Symbol_newVal (parent, name, flags, tpe, privateWithin)
2125
+
2112
2126
/** Definition not available */
2113
2127
def noSymbol (using ctx : Context ): Symbol =
2114
2128
internal.Symbol_noSymbol
@@ -2772,19 +2786,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
2772
2786
2773
2787
/** Bind the `rhs` to a `val` and use it in `body` */
2774
2788
def let (rhs : Term )(body : Ident => Term )(using ctx : Context ): Term = {
2775
- import scala .quoted .QuoteContext
2776
- given QuoteContext = new QuoteContext (this )
2777
- val expr = (rhs.seal: @ unchecked) match {
2778
- case ' { $rhsExpr : $t } =>
2779
- ' {
2780
- val x = $rhsExpr
2781
- $ {
2782
- val id = (' x ).unseal.asInstanceOf [Ident ]
2783
- body(id).seal
2784
- }
2785
- }
2786
- }
2787
- expr.unseal
2789
+ val sym = Symbol .newVal(ctx.owner, " x" , rhs.tpe.widen, Flags .EmptyFlags , Symbol .noSymbol)
2790
+ Block (List (ValDef (sym, Some (rhs))), body(Ref (sym).asInstanceOf [Ident ]))
2788
2791
}
2789
2792
2790
2793
/** Bind the given `terms` to names and use them in the `body` */
0 commit comments