@@ -2109,6 +2109,22 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
21092109 def newMethod (parent : Symbol , name : String , tpe : Type , flags : Flags , privateWithin : Symbol )(using ctx : Context ): Symbol =
21102110 internal.Symbol_newMethod (parent, name, flags, tpe, privateWithin)
21112111
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+
21122128 /** Definition not available */
21132129 def noSymbol (using ctx : Context ): Symbol =
21142130 internal.Symbol_noSymbol
@@ -2772,19 +2788,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
27722788
27732789 /** Bind the `rhs` to a `val` and use it in `body` */
27742790 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 ]))
27882793 }
27892794
27902795 /** Bind the given `terms` to names and use them in the `body` */
0 commit comments