File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,18 @@ object Tuple {
143
143
}
144
144
}
145
145
146
+ /**
147
+ * Use this type to widen a self-type to a tuple. E.g.
148
+ * ```
149
+ * val x: (1, 3) = (1, 3)
150
+ * val y: Widen[x.type] = x
151
+ * ```
152
+ */
153
+ type Widen [Tup <: Tuple ] <: Tuple = Tup match {
154
+ case EmptyTuple => EmptyTuple
155
+ case h *: t => h *: t
156
+ }
157
+
146
158
/** Given two tuples, `A1 *: ... *: An * At` and `B1 *: ... *: Bn *: Bt`
147
159
* where at least one of `At` or `Bt` is `EmptyTuple` or `Tuple`,
148
160
* returns the tuple type `(A1, B1) *: ... *: (An, Bn) *: Ct`
Original file line number Diff line number Diff line change @@ -42,13 +42,13 @@ package object compiletime {
42
42
43
43
inline def constValue [T ]: T = ???
44
44
45
- inline def constValueTuple [T <: Tuple ]: T =
45
+ inline def constValueTuple [T <: Tuple ]: Tuple . Widen [ T ] =
46
46
val res =
47
47
inline erasedValue[T ] match
48
48
case _ : EmptyTuple => EmptyTuple
49
49
case _ : (t *: ts) => constValue[t] *: constValueTuple[ts]
50
50
end match
51
- res.asInstanceOf [T ]
51
+ res.asInstanceOf [Tuple . Widen [ T ] ]
52
52
end constValueTuple
53
53
54
54
/** Summons first given matching one of the listed cases. E.g. in
@@ -83,13 +83,13 @@ package object compiletime {
83
83
* @tparam T the tuple containing the types of the values to be summoned
84
84
* @return the given values typed as elements of the tuple
85
85
*/
86
- inline def summonAll [T <: Tuple ]: T =
86
+ inline def summonAll [T <: Tuple ]: Tuple . Widen [ T ] =
87
87
val res =
88
88
inline erasedValue[T ] match
89
89
case _ : EmptyTuple => EmptyTuple
90
90
case _ : (t *: ts) => summonInline[t] *: summonAll[ts]
91
91
end match
92
- res.asInstanceOf [T ]
92
+ res.asInstanceOf [Tuple . Widen [ T ] ]
93
93
end summonAll
94
94
95
95
/** Succesor of a natural number where zero is the type 0 and successors are reduced as if the definition was
You can’t perform that action at this time.
0 commit comments