Skip to content

Commit 1ff0d17

Browse files
committed
Attempt to fix scala#4147: constrain type constructors less
Unfortunately this is currently broken because of the poly-kinded Nothing, we may end up doing something like: ?F[A] <:< Foo[A, B] ?F <:< Foo ?F := Nothing // OK, even though ?F has the wrong kind
1 parent abb6f36 commit 1ff0d17

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
662662
tycon1.dealias match {
663663
case tycon1: TypeParamRef =>
664664
(tycon1 == tycon2 ||
665-
canConstrain(tycon1) && tryInstantiate(tycon1, tycon2)) &&
665+
canConstrain(tycon1) && isSubType(tycon1, tycon2)) &&
666666
isSubArgs(args1, args2, tp1, tparams)
667667
case tycon1: TypeRef =>
668668
tycon2.dealias match {
@@ -801,7 +801,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
801801
case param1: TypeParamRef =>
802802
def canInstantiate = tp2 match {
803803
case AppliedType(tycon2, args2) =>
804-
tryInstantiate(param1, tycon2.ensureHK) && isSubArgs(args1, args2, tp1, tycon2.typeParams)
804+
isSubType(param1, tycon2.ensureHK) && isSubArgs(args1, args2, tp1, tycon2.typeParams)
805805
case _ =>
806806
false
807807
}

tests/pos/i4147.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Higher[F[_]]
2+
trait Super[A]
3+
trait Sub[A] extends Super[A]
4+
5+
object Test {
6+
implicit def higherSub: Higher[Sub] = ???
7+
implicit def deriv[F[_]](implicit bla: Higher[F]): F[String] = ???
8+
9+
implicit def deriv[F <: [X] => Super[X]]: F[Int] = ???
10+
11+
val x: Super[String] = deriv
12+
}

tests/pos/i4147b.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait Bar[F[_]]
2+
trait Foo[A]
3+
trait Qux[A] extends Foo[A]
4+
object Qux {
5+
implicit def string: Qux[String] = ???
6+
implicit def bar: Bar[Qux] = ???
7+
}
8+
9+
case class Problem[A](a: A)
10+
object Problem {
11+
import Qux._
12+
implicit def deriv[F[_]](implicit bla: Bar[F], baz: F[String]): F[Problem[String]] = ???
13+
implicitly[Foo[Problem[String]]](deriv)
14+
}

0 commit comments

Comments
 (0)