@@ -341,8 +341,21 @@ object desugar {
341341 (if (args.isEmpty) tycon else AppliedTypeTree (tycon, args))
342342 .withPos(cdef.pos.startPos)
343343
344- def appliedRef (tycon : Tree , tparams : List [TypeDef ] = constrTparams) =
345- appliedTypeTree(tycon, tparams map refOfDef)
344+ def appliedRef (tycon : Tree , tparams : List [TypeDef ] = constrTparams, widenHK : Boolean = false ) = {
345+ var targs = for (tparam <- tparams) yield {
346+ val targ = refOfDef(tparam)
347+ def fullyApplied (tparam : Tree ): Tree = tparam match {
348+ case TypeDef (_, LambdaTypeTree (tparams, body)) =>
349+ AppliedTypeTree (targ, tparams.map(_ => TypeBoundsTree (EmptyTree , EmptyTree )))
350+ case TypeDef (_, rhs : DerivedTypeTree ) =>
351+ fullyApplied(rhs.watched)
352+ case _ =>
353+ targ
354+ }
355+ if (widenHK) fullyApplied(tparam) else targ
356+ }
357+ appliedTypeTree(tycon, targs)
358+ }
346359
347360 // a reference to the class type bound by `cdef`, with type parameters coming from the constructor
348361 val classTypeRef = appliedRef(classTycon)
@@ -431,12 +444,16 @@ object desugar {
431444 //
432445 // implicit def eqInstance[T1$1, ..., Tn$1, T1$2, ..., Tn$2](implicit
433446 // ev1: Eq[T1$1, T1$2], ..., evn: Eq[Tn$1, Tn$2]])
434- // : Eq[C[T1$1, ..., Tn$1], C[T1$2, ..., Tn$2]] = Eq
447+ // : Eq[C[T1$, ..., Tn$1], C[T1$2, ..., Tn$2]] = Eq
448+ //
449+ // If any of the T_i are higher-kinded, say `Ti[X1 >: L1 <: U1, ..., Xm >: Lm <: Um]`,
450+ // the corresponding type parameters for $ev_i are `Ti$1[_, ..., _], Ti$2[_, ..., _]`
451+ // (with m underscores `_`).
435452 def eqInstance = {
436453 val leftParams = constrTparams.map(derivedTypeParam(_, " $1" ))
437454 val rightParams = constrTparams.map(derivedTypeParam(_, " $2" ))
438455 val subInstances = (leftParams, rightParams).zipped.map((param1, param2) =>
439- appliedRef(ref(defn.EqType ), List (param1, param2)))
456+ appliedRef(ref(defn.EqType ), List (param1, param2), widenHK = true ))
440457 DefDef (
441458 name = nme.eqInstance,
442459 tparams = leftParams ++ rightParams,
0 commit comments