diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 5ecb0ee01ec0..309aa41e46bb 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1208,8 +1208,15 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling def directionalRecur(tp1: Type, tp2: Type): Boolean = if fromBelow then recur(tp2, tp1) else recur(tp1, tp2) - val otherTycon = other.tycon - val otherArgs = other.args + // If the arity of the type constructors does not match, dealias to avoid creating type lambdas. + val otherDealiased = + if other.args.hasSameLengthAs(args) then other + else other.dealias match + case dealiasedType: AppliedType if dealiasedType.args.hasSameLengthAs(args) => + dealiasedType + case _ => other + val otherTycon = otherDealiased.tycon + val otherArgs = otherDealiased.args val d = otherArgs.length - args.length d >= 0 && { @@ -1234,7 +1241,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling otherTycon rollbackConstraintsUnless: (assumedTrue(tycon) || directionalIsSubType(tycon, adaptedTycon)) - && directionalRecur(adaptedTycon.appliedTo(args), other) + && directionalRecur(adaptedTycon.appliedTo(args), otherDealiased) } } end compareAppliedTypeParamRef diff --git a/tests/pos/dealias-hk-typeparam.scala b/tests/pos/dealias-hk-typeparam.scala new file mode 100644 index 000000000000..e39d9ffd1d12 --- /dev/null +++ b/tests/pos/dealias-hk-typeparam.scala @@ -0,0 +1,8 @@ +type Result[F[_], Err, Res] = F[Either[Err, Res]] + +trait TypeClass[F[_]] + +def id[F[_]: TypeClass, A](x: F[A]) = x + +def test[F[_]: TypeClass](x: Result[F, String, Int]) = + id(x) \ No newline at end of file