diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index d7bf75f8bf73..1443cb929b33 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -462,20 +462,26 @@ object Implicits: val ctx1 = ctx.fresh.setExploreTyperState() ctx1.typerState.constraint = constraint inContext(ctx1) { - val map = new TypeMap { - def apply(t: Type): Type = t match { + val map = new TypeMap: + def apply(t: Type): Type = t match case t: TypeParamRef => - constraint.entry(t) match { - case NoType => t - case bounds: TypeBounds => TypeComparer.fullBounds(t) + constraint.entry(t) match + case NoType | _: TypeBounds => t case t1 => t1 - } case t: TypeVar => t.instanceOpt.orElse(apply(t.origin)) case _ => mapOver(t) - } - } + + override def mapArgs(args: List[Type], tparams: List[ParamInfo]) = + args.mapConserve { + case t: TypeParamRef => + constraint.entry(t) match + case bounds: TypeBounds => TypeComparer.fullBounds(t) + case _ => this(t) + case t => this(t) + } + end map map(tp) } diff --git a/tests/neg/i13987.scala b/tests/neg/i13987.scala new file mode 100644 index 000000000000..b27cd444cda6 --- /dev/null +++ b/tests/neg/i13987.scala @@ -0,0 +1,16 @@ +sealed trait Xa[T] +sealed trait Mu[T] extends Xa[T] +object Xa { + // bad + implicit def convertMu[X[x] <: Xa[x], A, B](implicit t: X[A] with Xa[A]): X[B] = t.asInstanceOf[X[B]] + // good +// implicit def convertMu[X[x] <: Xa[x], A, B](implicit t: X[A] with Mu[A]): X[B] = t.asInstanceOf[X[B]] +} +object Mu { + implicit def mu: Mu[Int] = new Mu[Int] {} +} + +object App extends App { + def constrain(a: Mu[Long]): Unit = println(a) + constrain(Xa.convertMu) // error +} \ No newline at end of file