@@ -2109,6 +2109,22 @@ 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
+ * Note: Also see Reflection.let
2119
+ *
2120
+ * @param flags extra flags to with which the symbol should be constructed
2121
+ * @param privateWithin the symbol within which this new method symbol should be private. May be noSymbol.
2122
+ * @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be
2123
+ * direct or indirect children of the reflection context's owner.
2124
+ */
2125
+ def newVal (parent : Symbol , name : String , tpe : Type , flags : Flags , privateWithin : Symbol )(using ctx : Context ): Symbol =
2126
+ internal.Symbol_newVal (parent, name, flags, tpe, privateWithin)
2127
+
2112
2128
/** Definition not available */
2113
2129
def noSymbol (using ctx : Context ): Symbol =
2114
2130
internal.Symbol_noSymbol
@@ -2772,19 +2788,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
2772
2788
2773
2789
/** Bind the `rhs` to a `val` and use it in `body` */
2774
2790
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
2791
+ val sym = Symbol .newVal(ctx.owner, " x" , rhs.tpe.widen, Flags .EmptyFlags , Symbol .noSymbol)
2792
+ Block (List (ValDef (sym, Some (rhs))), body(Ref (sym).asInstanceOf [Ident ]))
2788
2793
}
2789
2794
2790
2795
/** Bind the given `terms` to names and use them in the `body` */
0 commit comments