@@ -85,16 +85,28 @@ package object compiletime {
85
85
// implemented in dotty.tools.dotc.typer.Inliner
86
86
error(" Compiler bug: `constValue` was not evaluated by the compiler" )
87
87
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
+
88
100
/** Given a tuple type `(X1, ..., Xn)`, returns a tuple value
89
101
* `(constValue[X1], ..., constValue[Xn])`.
90
102
*/
91
- inline def constValueTuple [T <: Tuple ]: Tuple . Widen [T ]=
103
+ inline def constValueTuple [T <: Tuple ]: Widen [T ]=
92
104
val res =
93
105
inline erasedValue[T ] match
94
106
case _ : EmptyTuple => EmptyTuple
95
107
case _ : (t *: ts) => constValue[t] *: constValueTuple[ts]
96
108
end match
97
- res.asInstanceOf [Tuple . Widen [T ]]
109
+ res.asInstanceOf [Widen [T ]]
98
110
end constValueTuple
99
111
100
112
/** Summons first given matching one of the listed cases. E.g. in
@@ -129,13 +141,13 @@ package object compiletime {
129
141
* @tparam T the tuple containing the types of the values to be summoned
130
142
* @return the given values typed as elements of the tuple
131
143
*/
132
- inline def summonAll [T <: Tuple ]: Tuple . Widen [T ] =
144
+ inline def summonAll [T <: Tuple ]: Widen [T ] =
133
145
val res =
134
146
inline erasedValue[T ] match
135
147
case _ : EmptyTuple => EmptyTuple
136
148
case _ : (t *: ts) => summonInline[t] *: summonAll[ts]
137
149
end match
138
- res.asInstanceOf [Tuple . Widen [T ]]
150
+ res.asInstanceOf [Widen [T ]]
139
151
end summonAll
140
152
141
153
/** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was
0 commit comments