Skip to content

Commit 83ece6a

Browse files
committed
Fix owner in ValDef.let
1 parent ee64418 commit 83ece6a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

compiler/src/scala/quoted/internal/impl/QuoteContextImpl.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,14 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl
278278
def unapply(vdef: ValDef): Option[(String, TypeTree, Option[Term])] =
279279
Some((vdef.name.toString, vdef.tpt, optional(vdef.rhs)))
280280

281-
def let(name: String, rhs: Term)(body: Ident => Term): Term =
282-
val vdef = tpd.SyntheticValDef(name.toTermName, rhs)
281+
def let(name: String, rhs: Term)(body: Ident => Term)(using owner: Owner): Term =
282+
val vdef = tpd.SyntheticValDef(name.toTermName, rhs)(using ctx.withOwner(owner))
283283
val ref = tpd.ref(vdef.symbol).asInstanceOf[Ident]
284284
Block(List(vdef), body(ref))
285285

286-
def let(terms: List[Term])(body: List[Ident] => Term): Term =
287-
val vdefs = terms.map(term => tpd.SyntheticValDef("x".toTermName, term))
286+
def let(terms: List[Term])(body: List[Ident] => Term)(using owner: Owner): Term =
287+
val ctx1 = ctx.withOwner(owner)
288+
val vdefs = terms.map(term => tpd.SyntheticValDef("x".toTermName, term)(using ctx1))
288289
val refs = vdefs.map(vdef => tpd.ref(vdef.symbol).asInstanceOf[Ident])
289290
Block(vdefs, body(refs))
290291
end ValDef

library/src/scala/quoted/QuoteContext.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,13 @@ trait QuoteContext { self: internal.QuoteUnpickler & internal.QuoteMatching =>
388388
def unapply(vdef: ValDef): Option[(String, TypeTree, Option[Term])]
389389

390390
/** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }` */
391-
def let(name: String, rhs: Term)(body: Ident => Term): Term
391+
def let(name: String, rhs: Term)(body: Ident => Term)(using owner: Owner): Term
392392

393393
/** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }` */
394-
def let(rhs: Term)(body: Ident => Term): Term = let("x", rhs)(body)
394+
def let(rhs: Term)(body: Ident => Term)(using owner: Owner): Term = let("x", rhs)(body)
395395

396396
/** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }` */
397-
def let(terms: List[Term])(body: List[Ident] => Term): Term
397+
def let(terms: List[Term])(body: List[Ident] => Term)(using owner: Owner): Term
398398
}
399399

400400
given ValDefMethods as ValDefMethods = ValDefMethodsImpl

0 commit comments

Comments
 (0)