@@ -2109,6 +2109,20 @@ 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+ * @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+
21122126 /** Definition not available */
21132127 def noSymbol (using ctx : Context ): Symbol =
21142128 internal.Symbol_noSymbol
@@ -2772,19 +2786,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
27722786
27732787 /** Bind the `rhs` to a `val` and use it in `body` */
27742788 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 ]))
27882791 }
27892792
27902793 /** Bind the given `terms` to names and use them in the `body` */
0 commit comments