File tree 2 files changed +13
-8
lines changed
compiler/src/dotty/tools/dotc/quoted
2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -707,8 +707,10 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext:
707
707
def unapply (x : Block ): Option [(List [Statement ], Term )] =
708
708
Some ((x.statements, x.expr))
709
709
710
- def let (rhs : Term )(body : Ident => Term ): Term =
711
- let(List (rhs))(x => body(x.head))
710
+ def let (name : String , rhs : Term )(body : Ident => Term ): Term =
711
+ val vdef = tpd.SyntheticValDef (name.toTermName, rhs)
712
+ val ref = tpd.ref(vdef.symbol).asInstanceOf [Ident ]
713
+ Block (List (vdef), body(ref))
712
714
713
715
def let (terms : List [Term ])(body : List [Ident ] => Term ): Term =
714
716
val vdefs = terms.map(term => tpd.SyntheticValDef (" x" .toTermName, term))
Original file line number Diff line number Diff line change @@ -818,16 +818,19 @@ trait Reflection { reflection =>
818
818
/** Creates a block `{ <statements: List[Statement]>; <expr: Term> }` */
819
819
def apply (stats : List [Statement ], expr : Term ): Block
820
820
821
- /** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }` */
822
- def let (rhs : Term )(body : Ident => Term ): Term
823
-
824
- /** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }` */
825
- def let (terms : List [Term ])(body : List [Ident ] => Term ): Term
826
-
827
821
def copy (original : Tree )(stats : List [Statement ], expr : Term ): Block
828
822
829
823
/** Matches a block `{ <statements: List[Statement]>; <expr: Term> }` */
830
824
def unapply (x : Block ): Option [(List [Statement ], Term )]
825
+
826
+ /** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }` */
827
+ def let (name : String , rhs : Term )(body : Ident => Term ): Term
828
+
829
+ /** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }` */
830
+ def let (rhs : Term )(body : Ident => Term ): Term = let(" x" , rhs)(body)
831
+
832
+ /** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }` */
833
+ def let (terms : List [Term ])(body : List [Ident ] => Term ): Term
831
834
}
832
835
833
836
given BlockMethods as BlockMethods = BlockMethodsImpl
You can’t perform that action at this time.
0 commit comments