Skip to content

Commit 84e62c3

Browse files
committed
Fix #3976: Fix Eq method for enums with higher-kinded parameters
1 parent 39980f3 commit 84e62c3

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

tests/pos/i3976.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum class Hoge[F[_]]

0 commit comments

Comments
 (0)