@@ -537,45 +537,6 @@ object desugar {
537
537
if (isEnum)
538
538
parents1 = parents1 :+ ref(defn.EnumType )
539
539
540
- // The Eq instance for an Enum class. For an enum class
541
- //
542
- // enum class C[T1, ..., Tn]
543
- //
544
- // we generate:
545
- //
546
- // implicit def eqInstance[T1$1, ..., Tn$1, T1$2, ..., Tn$2](implicit
547
- // ev1: Eq[T1$1, T1$2], ..., evn: Eq[Tn$1, Tn$2]])
548
- // : Eq[C[T1$, ..., Tn$1], C[T1$2, ..., Tn$2]] = Eq
549
- //
550
- // Higher-kinded type arguments `Ti` are omitted as evidence parameters.
551
- //
552
- // FIXME: This is too simplistic. Instead of just generating evidence arguments
553
- // for every first-kinded type parameter, we should look instead at the
554
- // actual types occurring in cases and derive parameters from these. E.g. in
555
- //
556
- // enum HK[F[_]] {
557
- // case C1(x: F[Int]) extends HK[F[Int]]
558
- // case C2(y: F[String]) extends HL[F[Int]]
559
- //
560
- // we would need evidence parameters for `F[Int]` and `F[String]`
561
- // We should generate Eq instances with the techniques
562
- // of typeclass derivation once that is available.
563
- def eqInstance = {
564
- val leftParams = constrTparams.map(derivedTypeParam(_, " $1" ))
565
- val rightParams = constrTparams.map(derivedTypeParam(_, " $2" ))
566
- val subInstances =
567
- for ((param1, param2) <- leftParams `zip` rightParams if ! isHK(param1))
568
- yield appliedRef(ref(defn.EqType ), List (param1, param2), widenHK = true )
569
- DefDef (
570
- name = nme.eqInstance,
571
- tparams = leftParams ++ rightParams,
572
- vparamss = if (subInstances.isEmpty) Nil else List (makeImplicitParameters(subInstances)),
573
- tpt = appliedTypeTree(ref(defn.EqType ),
574
- appliedRef(classTycon, leftParams) :: appliedRef(classTycon, rightParams) :: Nil ),
575
- rhs = ref(defn.EqModule .termRef)).withFlags(Synthetic | Implicit )
576
- }
577
- def eqInstances = if (isEnum) eqInstance :: Nil else Nil
578
-
579
540
// derived type classes of non-module classes go to their companions
580
541
val (clsDerived, companionDerived) =
581
542
if (mods.is(Module )) (impl.derived, Nil ) else (Nil , impl.derived)
@@ -594,7 +555,7 @@ object desugar {
594
555
mdefs
595
556
}
596
557
597
- val companionMembers = defaultGetters ::: eqInstances ::: enumCases
558
+ val companionMembers = defaultGetters ::: enumCases
598
559
599
560
// The companion object definitions, if a companion is needed, Nil otherwise.
600
561
// companion definitions include:
@@ -644,7 +605,7 @@ object desugar {
644
605
}
645
606
companionDefs(companionParent, applyMeths ::: unapplyMeth :: companionMembers)
646
607
}
647
- else if (companionMembers.nonEmpty || companionDerived.nonEmpty)
608
+ else if (companionMembers.nonEmpty || companionDerived.nonEmpty || isEnum )
648
609
companionDefs(anyRef, companionMembers)
649
610
else if (isValueClass) {
650
611
impl.constr.vparamss match {
0 commit comments