Skip to content

Commit c486c0e

Browse files
committed
Move Tuple.Widen to compiletime package
1 parent 4265f08 commit c486c0e

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

library/src/scala/Tuple.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,6 @@ object Tuple {
142142
}
143143
}
144144

145-
/**
146-
* Use this type to widen a self-type to a tuple. E.g.
147-
* ```
148-
* val x: (1, 3) = (1, 3)
149-
* val y: Widen[x.type] = x
150-
* ```
151-
*/
152-
type Widen[Tup <: Tuple] <: Tuple = Tup match {
153-
case EmptyTuple => EmptyTuple
154-
case h *: t => h *: t
155-
}
156-
157145
/** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt`
158146
* where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`,
159147
* returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: Ct`

library/src/scala/compiletime/package.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,28 @@ package object compiletime {
8585
// implemented in dotty.tools.dotc.typer.Inliner
8686
error("Compiler bug: `constValue` was not evaluated by the compiler")
8787

88+
/**
89+
* Use this type to widen a self-type to a tuple. E.g.
90+
* ```
91+
* val x: (1, 3) = (1, 3)
92+
* val y: Widen[x.type] = x
93+
* ```
94+
*/
95+
type Widen[Tup <: Tuple] <: Tuple = Tup match {
96+
case EmptyTuple => EmptyTuple
97+
case h *: t => h *: t
98+
}
99+
88100
/** Given a tuple type `(X1, ..., Xn)`, returns a tuple value
89101
* `(constValue[X1], ..., constValue[Xn])`.
90102
*/
91-
inline def constValueTuple[T <: Tuple]: Tuple.Widen[T]=
103+
inline def constValueTuple[T <: Tuple]: Widen[T]=
92104
val res =
93105
inline erasedValue[T] match
94106
case _: EmptyTuple => EmptyTuple
95107
case _: (t *: ts) => constValue[t] *: constValueTuple[ts]
96108
end match
97-
res.asInstanceOf[Tuple.Widen[T]]
109+
res.asInstanceOf[Widen[T]]
98110
end constValueTuple
99111

100112
/** Summons first given matching one of the listed cases. E.g. in
@@ -129,13 +141,13 @@ package object compiletime {
129141
* @tparam T the tuple containing the types of the values to be summoned
130142
* @return the given values typed as elements of the tuple
131143
*/
132-
inline def summonAll[T <: Tuple]: Tuple.Widen[T] =
144+
inline def summonAll[T <: Tuple]: Widen[T] =
133145
val res =
134146
inline erasedValue[T] match
135147
case _: EmptyTuple => EmptyTuple
136148
case _: (t *: ts) => summonInline[t] *: summonAll[ts]
137149
end match
138-
res.asInstanceOf[Tuple.Widen[T]]
150+
res.asInstanceOf[Widen[T]]
139151
end summonAll
140152

141153
/** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was

library/src/scala/util/FromDigits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ object FromDigits {
156156
x
157157
}
158158

159-
given BigIntFromDigits as FromDigits.WithRadix[BigInt] {
159+
given BigIntFromDigits as WithRadix[BigInt] {
160160
def fromDigits(digits: String, radix: Int): BigInt = BigInt(digits, radix)
161161
}
162162

163-
given BigDecimalFromDigits as FromDigits.Floating[BigDecimal] {
163+
given BigDecimalFromDigits as Floating[BigDecimal] {
164164
def fromDigits(digits: String): BigDecimal = BigDecimal(digits)
165165
}
166166
}

0 commit comments

Comments
 (0)