Skip to content

Commit 6eace06

Browse files
committed
Drop unused parameter
1 parent 06125b5 commit 6eace06

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

tests/run/typeclass-derivation2.scala

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ trait Deriving {
55
import Deriving._
66

77
/** A mirror of case with ordinal number `ordinal` and elements as given by `Product` */
8-
def mirror[T](ordinal: Int, product: Product): CaseMirror[T] =
9-
new CaseMirror(this, ordinal, product)
8+
def mirror(ordinal: Int, product: Product): Mirror =
9+
new Mirror(this, ordinal, product)
1010

1111
/** A mirror with elements given as an array */
12-
def mirror[T](ordinal: Int, elems: Array[AnyRef]): CaseMirror[T] =
12+
def mirror(ordinal: Int, elems: Array[AnyRef]): Mirror =
1313
mirror(ordinal, new ArrayProduct(elems))
1414

1515
/** A mirror with an initial empty array of `numElems` elements, to be filled in. */
16-
def mirror[T](ordinal: Int, numElems: Int): CaseMirror[T] =
16+
def mirror(ordinal: Int, numElems: Int): Mirror =
1717
mirror(ordinal, new Array[AnyRef](numElems))
1818

1919
/** A mirror of a case with no elements */
20-
def mirror[T](ordinal: Int): CaseMirror[T] =
20+
def mirror(ordinal: Int): Mirror =
2121
mirror(ordinal, EmptyProduct)
2222

2323
/** The case and element labels of the described ADT as encoded strings. */
@@ -46,7 +46,7 @@ object Deriving {
4646
* @param ordinal The ordinal value of the case in the list of the ADT's cases
4747
* @param elems The elements of the case
4848
*/
49-
class CaseMirror[+T](val deriving: Deriving, val ordinal: Int, val elems: Product) {
49+
class Mirror(val deriving: Deriving, val ordinal: Int, val elems: Product) {
5050

5151
/** The `n`'th element of this generic case */
5252
def apply(n: Int): Any = elems.productElement(n)
@@ -64,16 +64,18 @@ object Deriving {
6464
abstract class Reflected[T] {
6565

6666
/** The case mirror corresponding to ADT instance `x` */
67-
def reflect(x: T): CaseMirror[T]
67+
def reflect(x: T): Mirror
6868

6969
/** The ADT instance corresponding to given `mirror` */
70-
def reify(mirror: CaseMirror[T]): T
70+
def reify(mirror: Mirror): T
7171

7272
/** The companion object of the ADT */
7373
def deriving: Deriving
7474
}
7575

76-
/** The shape of an ADT in a sum of products representation */
76+
/** The shape of an ADT.
77+
* This is eithe a product (`Case`) or a sum (`Cases`) of products.
78+
*/
7779
enum Shape {
7880

7981
/** A sum with alternative types `Alts` */
@@ -84,7 +86,7 @@ object Deriving {
8486
}
8587

8688
/** Every generic derivation starts with a typeclass instance of this type.
87-
* It informs that type `T` has shape `S` and also allows runtime reflection on `T`.
89+
* It informs that type `T` has shape `S` and also implements runtime reflection on `T`.
8890
*/
8991
abstract class Shaped[T, S <: Shape] extends Reflected[T]
9092

@@ -121,14 +123,14 @@ object Lst extends Deriving {
121123
Shape.Case[Nil.type, Unit]
122124
)]
123125

124-
val NilMirror = mirror[Nil.type](1)
126+
val NilMirror = mirror(1)
125127

126128
implicit def lstShape[T]: Shaped[Lst[T], Shape[T]] = new {
127-
def reflect(xs: Lst[T]): CaseMirror[Lst[T]] = xs match {
128-
case xs: Cons[T] => mirror[Cons[T]](0, xs)
129+
def reflect(xs: Lst[T]): Mirror = xs match {
130+
case xs: Cons[T] => mirror(0, xs)
129131
case Nil => NilMirror
130132
}
131-
def reify(c: CaseMirror[Lst[T]]): Lst[T] = c.ordinal match {
133+
def reify(c: Mirror): Lst[T] = c.ordinal match {
132134
case 0 => Cons[T](c(0).asInstanceOf, c(1).asInstanceOf)
133135
case 1 => Nil
134136
}
@@ -154,8 +156,8 @@ object Pair extends Deriving {
154156

155157
implicit def pairShape[T]: Shaped[Pair[T], Shape[T]] = new {
156158
def reflect(xy: Pair[T]) =
157-
mirror[Pair[T]](0, xy)
158-
def reify(c: CaseMirror[Pair[T]]): Pair[T] =
159+
mirror(0, xy)
160+
def reify(c: Mirror): Pair[T] =
159161
Pair(c(0).asInstanceOf, c(1).asInstanceOf)
160162
def deriving = Pair
161163
}
@@ -180,7 +182,7 @@ object Eq {
180182
case eq: Eq[T] => eq.eql(x, y)
181183
}
182184

183-
inline def eqlElems[Elems <: Tuple](xs: CaseMirror[_], ys: CaseMirror[_], n: Int): Boolean =
185+
inline def eqlElems[Elems <: Tuple](xs: Mirror, ys: Mirror, n: Int): Boolean =
184186
inline erasedValue[Elems] match {
185187
case _: (elem *: elems1) =>
186188
tryEql[elem](xs(n).asInstanceOf, ys(n).asInstanceOf) &&
@@ -237,7 +239,7 @@ object Pickler {
237239
case pkl: Pickler[T] => pkl.pickle(buf, x)
238240
}
239241

240-
inline def pickleElems[Elems <: Tuple](buf: mutable.ListBuffer[Int], elems: CaseMirror[_], n: Int): Unit =
242+
inline def pickleElems[Elems <: Tuple](buf: mutable.ListBuffer[Int], elems: Mirror, n: Int): Unit =
241243
inline erasedValue[Elems] match {
242244
case _: (elem *: elems1) =>
243245
tryPickle[elem](buf, elems(n).asInstanceOf[elem])
@@ -276,11 +278,11 @@ object Pickler {
276278
inline def unpickleCase[T, Elems <: Tuple](r: Reflected[T], buf: mutable.ListBuffer[Int], ordinal: Int): T = {
277279
inline val size = constValue[Tuple.Size[Elems]]
278280
inline if (size == 0)
279-
r.reify(r.deriving.mirror[T](ordinal))
281+
r.reify(r.deriving.mirror(ordinal))
280282
else {
281283
val elems = new Array[Object](size)
282284
unpickleElems[Elems](buf, elems, 0)
283-
r.reify(r.deriving.mirror[T](ordinal, elems))
285+
r.reify(r.deriving.mirror(ordinal, elems))
284286
}
285287
}
286288

@@ -326,7 +328,7 @@ object Show {
326328
case s: Show[T] => s.show(x)
327329
}
328330

329-
inline def showElems[Elems <: Tuple](elems: CaseMirror[_], n: Int): List[String] =
331+
inline def showElems[Elems <: Tuple](elems: Mirror, n: Int): List[String] =
330332
inline erasedValue[Elems] match {
331333
case _: (elem *: elems1) =>
332334
val formal = elems.elementLabel(n)

0 commit comments

Comments
 (0)