From aed829800d9bb99dc72195faaca78a4bc1bfa9fc Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 29 May 2020 18:54:31 +0200 Subject: [PATCH] Avoid overloading of Expr.ofTuple This will improve error messages when implicits are missing or the complex type match constraints fail. --- community-build/community-projects/shapeless | 2 +- library/src-bootstrapped/scala/quoted/Expr.scala | 4 ++-- tests/run-macros/quote-toExprOfTuple/Macro_1.scala | 2 +- tests/run-macros/refined-selectable-macro/Macro_1.scala | 4 ++-- tests/run-staging/quote-toExprOfTuple.scala | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/community-build/community-projects/shapeless b/community-build/community-projects/shapeless index 5435ceb5993e..6341f38b67bd 160000 --- a/community-build/community-projects/shapeless +++ b/community-build/community-projects/shapeless @@ -1 +1 @@ -Subproject commit 5435ceb5993e4cbfff5ffd167d9ede56232008f7 +Subproject commit 6341f38b67bda8da258f678706de98e68d5762dd diff --git a/library/src-bootstrapped/scala/quoted/Expr.scala b/library/src-bootstrapped/scala/quoted/Expr.scala index e40d45566c91..7441e5d26306 100644 --- a/library/src-bootstrapped/scala/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/quoted/Expr.scala @@ -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() } @@ -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`. diff --git a/tests/run-macros/quote-toExprOfTuple/Macro_1.scala b/tests/run-macros/quote-toExprOfTuple/Macro_1.scala index 5ad1acd0cccc..0f023cbe4e5c 100644 --- a/tests/run-macros/quote-toExprOfTuple/Macro_1.scala +++ b/tests/run-macros/quote-toExprOfTuple/Macro_1.scala @@ -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)] } } diff --git a/tests/run-macros/refined-selectable-macro/Macro_1.scala b/tests/run-macros/refined-selectable-macro/Macro_1.scala index 15b1a7792d63..abaa69be1221 100644 --- a/tests/run-macros/refined-selectable-macro/Macro_1.scala +++ b/tests/run-macros/refined-selectable-macro/Macro_1.scala @@ -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] = { diff --git a/tests/run-staging/quote-toExprOfTuple.scala b/tests/run-staging/quote-toExprOfTuple.scala index 32aa75d21f4e..004b576a3d20 100644 --- a/tests/run-staging/quote-toExprOfTuple.scala +++ b/tests/run-staging/quote-toExprOfTuple.scala @@ -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