Skip to content

Commit 472c8ff

Browse files
authored
Merge pull request #14068 from dotty-staging/fix-13987
Don't generate illegal types when clarifying implicit errors
2 parents bc4d877 + b3ed0f8 commit 472c8ff

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

+14-8
Original file line numberDiff line numberDiff line change
@@ -470,20 +470,26 @@ object Implicits:
470470
val ctx1 = ctx.fresh.setExploreTyperState()
471471
ctx1.typerState.constraint = constraint
472472
inContext(ctx1) {
473-
val map = new TypeMap {
474-
def apply(t: Type): Type = t match {
473+
val map = new TypeMap:
474+
def apply(t: Type): Type = t match
475475
case t: TypeParamRef =>
476-
constraint.entry(t) match {
477-
case NoType => t
478-
case bounds: TypeBounds => TypeComparer.fullBounds(t)
476+
constraint.entry(t) match
477+
case NoType | _: TypeBounds => t
479478
case t1 => t1
480-
}
481479
case t: TypeVar =>
482480
t.instanceOpt.orElse(apply(t.origin))
483481
case _ =>
484482
mapOver(t)
485-
}
486-
}
483+
484+
override def mapArgs(args: List[Type], tparams: List[ParamInfo]) =
485+
args.mapConserve {
486+
case t: TypeParamRef =>
487+
constraint.entry(t) match
488+
case bounds: TypeBounds => TypeComparer.fullBounds(t)
489+
case _ => this(t)
490+
case t => this(t)
491+
}
492+
end map
487493
map(tp)
488494
}
489495

tests/neg/i13987.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sealed trait Xa[T]
2+
sealed trait Mu[T] extends Xa[T]
3+
object Xa {
4+
// bad
5+
implicit def convertMu[X[x] <: Xa[x], A, B](implicit t: X[A] with Xa[A]): X[B] = t.asInstanceOf[X[B]]
6+
// good
7+
// implicit def convertMu[X[x] <: Xa[x], A, B](implicit t: X[A] with Mu[A]): X[B] = t.asInstanceOf[X[B]]
8+
}
9+
object Mu {
10+
implicit def mu: Mu[Int] = new Mu[Int] {}
11+
}
12+
13+
object App extends App {
14+
def constrain(a: Mu[Long]): Unit = println(a)
15+
constrain(Xa.convertMu) // error
16+
}

0 commit comments

Comments
 (0)