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