From c486c0e247005dee09d67b84d3b42f6a006b9ade Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 20 Nov 2020 14:01:19 +0100 Subject: [PATCH] Move Tuple.Widen to compiletime package --- library/src/scala/Tuple.scala | 12 ------------ library/src/scala/compiletime/package.scala | 20 ++++++++++++++++---- library/src/scala/util/FromDigits.scala | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/library/src/scala/Tuple.scala b/library/src/scala/Tuple.scala index 7d8b828391d5..6587a71de2dc 100644 --- a/library/src/scala/Tuple.scala +++ b/library/src/scala/Tuple.scala @@ -142,18 +142,6 @@ object Tuple { } } - /** - * Use this type to widen a self-type to a tuple. E.g. - * ``` - * val x: (1, 3) = (1, 3) - * val y: Widen[x.type] = x - * ``` - */ - type Widen[Tup <: Tuple] <: Tuple = Tup match { - case EmptyTuple => EmptyTuple - case h *: t => h *: t - } - /** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt` * where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`, * returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: Ct` diff --git a/library/src/scala/compiletime/package.scala b/library/src/scala/compiletime/package.scala index 5ca5e4892bf0..ac0f03431b6e 100644 --- a/library/src/scala/compiletime/package.scala +++ b/library/src/scala/compiletime/package.scala @@ -85,16 +85,28 @@ package object compiletime { // implemented in dotty.tools.dotc.typer.Inliner error("Compiler bug: `constValue` was not evaluated by the compiler") + /** + * Use this type to widen a self-type to a tuple. E.g. + * ``` + * val x: (1, 3) = (1, 3) + * val y: Widen[x.type] = x + * ``` + */ + type Widen[Tup <: Tuple] <: Tuple = Tup match { + case EmptyTuple => EmptyTuple + case h *: t => h *: t + } + /** Given a tuple type `(X1, ..., Xn)`, returns a tuple value * `(constValue[X1], ..., constValue[Xn])`. */ - inline def constValueTuple[T <: Tuple]: Tuple.Widen[T]= + inline def constValueTuple[T <: Tuple]: Widen[T]= val res = inline erasedValue[T] match case _: EmptyTuple => EmptyTuple case _: (t *: ts) => constValue[t] *: constValueTuple[ts] end match - res.asInstanceOf[Tuple.Widen[T]] + res.asInstanceOf[Widen[T]] end constValueTuple /** Summons first given matching one of the listed cases. E.g. in @@ -129,13 +141,13 @@ package object compiletime { * @tparam T the tuple containing the types of the values to be summoned * @return the given values typed as elements of the tuple */ - inline def summonAll[T <: Tuple]: Tuple.Widen[T] = + inline def summonAll[T <: Tuple]: Widen[T] = val res = inline erasedValue[T] match case _: EmptyTuple => EmptyTuple case _: (t *: ts) => summonInline[t] *: summonAll[ts] end match - res.asInstanceOf[Tuple.Widen[T]] + res.asInstanceOf[Widen[T]] end summonAll /** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was diff --git a/library/src/scala/util/FromDigits.scala b/library/src/scala/util/FromDigits.scala index 5fb925dc8f13..fd33c1883b7b 100644 --- a/library/src/scala/util/FromDigits.scala +++ b/library/src/scala/util/FromDigits.scala @@ -156,11 +156,11 @@ object FromDigits { x } - given BigIntFromDigits as FromDigits.WithRadix[BigInt] { + given BigIntFromDigits as WithRadix[BigInt] { def fromDigits(digits: String, radix: Int): BigInt = BigInt(digits, radix) } - given BigDecimalFromDigits as FromDigits.Floating[BigDecimal] { + given BigDecimalFromDigits as Floating[BigDecimal] { def fromDigits(digits: String): BigDecimal = BigDecimal(digits) } }