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