Skip to content

Avoid overloading of Expr.ofTuple #9078

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
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
4 changes: 2 additions & 2 deletions library/src-bootstrapped/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ object Expr {
* to an expression equivalent to
* `'{ ($e1, $e2, ...) }` typed as an `Expr[Tuple]`
*/
def ofTuple(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] = {
def ofTupleFromSeq(seq: Seq[Expr[Any]])(using qctx: QuoteContext): Expr[Tuple] = {
seq match {
case Seq() =>
'{ Tuple() }
Expand Down Expand Up @@ -184,7 +184,7 @@ object Expr {
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */
def ofTuple[T <: Tuple: Tuple.IsMappedBy[Expr]: Type](tup: T)(using qctx: QuoteContext): Expr[Tuple.InverseMap[T, Expr]] = {
val elems: Seq[Expr[Any]] = tup.asInstanceOf[Product].productIterator.toSeq.asInstanceOf[Seq[Expr[Any]]]
ofTuple(elems).cast[Tuple.InverseMap[T, Expr]]
ofTupleFromSeq(elems).cast[Tuple.InverseMap[T, Expr]]
}

/** Find an implicit of type `T` in the current scope given by `qctx`.
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/quote-toExprOfTuple/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Macro {
import util._

val seq = List(t0, t1)
val res = Expr.ofTuple(seq)
val res = Expr.ofTupleFromSeq(seq)
res.cast[(T0, T1)]
}
}
4 changes: 2 additions & 2 deletions tests/run-macros/refined-selectable-macro/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ object Macro {
def tupleElem(name: String, info: Type): Expr[Any] = {
val nameExpr = Expr(name)
info.seal match { case '[$qType] =>
Expr.ofTuple(Seq(nameExpr, '{ $s.selectDynamic($nameExpr).asInstanceOf[$qType] }))
Expr.ofTupleFromSeq(Seq(nameExpr, '{ $s.selectDynamic($nameExpr).asInstanceOf[$qType] }))
}
}

val ret = rec(repr).reverse.map(e => tupleElem(e._1, e._2))

Expr.ofTuple(ret)
Expr.ofTupleFromSeq(ret)
}

private def fromTupleImpl[T: Type](s: Expr[Tuple], newRecord: Expr[Array[(String, Any)] => T])(using qctx:QuoteContext) : Expr[Any] = {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-staging/quote-toExprOfTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Test {
def main(args: Array[String]): Unit = {
for (n <- 0 to 25) {
prev = 0
println(run { Expr.ofTuple(Seq.fill(n)('{next})) })
println(run { Expr.ofTupleFromSeq(Seq.fill(n)('{next})) })
}
}
var prev = 0
Expand Down