Skip to content

Fix type of let reference #12619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def unapply(vdef: ValDef): (String, TypeTree, Option[Term]) =
(vdef.name.toString, vdef.tpt, optional(vdef.rhs))

def let(owner: Symbol, name: String, rhs: Term)(body: Ident => Term): Term =
def let(owner: Symbol, name: String, rhs: Term)(body: Ref => Term): Term =
val vdef = tpd.SyntheticValDef(name.toTermName, rhs)(using ctx.withOwner(owner))
val ref = tpd.ref(vdef.symbol).asInstanceOf[Ident]
val ref = tpd.ref(vdef.symbol).asInstanceOf[Ref]
Block(List(vdef), body(ref))

def let(owner: Symbol, terms: List[Term])(body: List[Ident] => Term): Term =
def let(owner: Symbol, terms: List[Term])(body: List[Ref] => Term): Term =
val ctx1 = ctx.withOwner(owner)
val vdefs = terms.map(term => tpd.SyntheticValDef("x".toTermName, term)(using ctx1))
val refs = vdefs.map(vdef => tpd.ref(vdef.symbol).asInstanceOf[Ident])
val refs = vdefs.map(vdef => tpd.ref(vdef.symbol).asInstanceOf[Ref])
Block(vdefs, body(refs))
end ValDef

Expand Down
6 changes: 3 additions & 3 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,14 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
def unapply(vdef: ValDef): (String, TypeTree, Option[Term])

/** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }` */
def let(owner: Symbol, name: String, rhs: Term)(body: Ident => Term): Term
def let(owner: Symbol, name: String, rhs: Term)(body: Ref => Term): Term

/** Creates a block `{ val x = <rhs: Term>; <body(x): Term> }` */
def let(owner: Symbol, rhs: Term)(body: Ident => Term): Term =
def let(owner: Symbol, rhs: Term)(body: Ref => Term): Term =
let(owner, "x", rhs)(body)

/** Creates a block `{ val x1 = <terms(0): Term>; ...; val xn = <terms(n-1): Term>; <body(List(x1, ..., xn)): Term> }` */
def let(owner: Symbol, terms: List[Term])(body: List[Ident] => Term): Term
def let(owner: Symbol, terms: List[Term])(body: List[Ref] => Term): Term
}

/** Makes extension methods on `ValDef` available without any imports */
Expand Down