From 3c4080299643724d33bfdc470a078052448f42f4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 6 Mar 2020 09:29:52 +0100 Subject: [PATCH] Fix #6561: Avoid double bounds instantiation --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 6 +++++- tests/pos/i6561.scala | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i6561.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index f94370bc7803..d53e0ac480ca 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -84,7 +84,11 @@ object Checking { val orderedArgs = if (hasNamedArg(args)) tparams.map(argNamed) else args val bounds = tparams.map(_.paramInfoAsSeenFrom(tree.tpe).bounds) def instantiate(bound: Type, args: List[Type]) = - HKTypeLambda.fromParams(tparams, bound).appliedTo(args) + tparams match + case LambdaParam(lam, _) :: _ => + HKTypeLambda.fromParams(tparams, bound).appliedTo(args) + case _ => + bound // paramInfoAsSeenFrom already took care of instantiation in this case if (boundsCheck) checkBounds(orderedArgs, bounds, instantiate, tree.tpe) def checkWildcardApply(tp: Type): Unit = tp match { diff --git a/tests/pos/i6561.scala b/tests/pos/i6561.scala new file mode 100644 index 000000000000..fd959edfe81f --- /dev/null +++ b/tests/pos/i6561.scala @@ -0,0 +1,7 @@ +trait Foo[V] +class Inv[A](a: A) + +trait Bar[K <: Foo[V], V] { + // ERROR: Type argument Foo[Inv[V]] does not conform to upper bound Foo[Inv[Inv[V]]] + def test(): Bar[Foo[Inv[V]], Inv[V]] +} \ No newline at end of file