Skip to content

Commit d357cb7

Browse files
committed
Fix subtyping of hk types with wildcard arguments
Argument comparison of hk types did not take into account that the compared types could have themselves wildcard arguments.
1 parent 23be74b commit d357cb7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,14 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
757757
if (args1.isEmpty) args2.isEmpty
758758
else args2.nonEmpty && {
759759
val v = tparams.head.paramVariance
760-
(v > 0 || isSubType(args2.head, args1.head)) &&
761-
(v < 0 || isSubType(args1.head, args2.head))
760+
def isSub(tp1: Type, tp2: Type) = tp2 match {
761+
case tp2: TypeBounds =>
762+
tp2.contains(tp1)
763+
case _ =>
764+
(v > 0 || isSubType(tp2, tp1)) &&
765+
(v < 0 || isSubType(tp1, tp2))
766+
}
767+
isSub(args1.head, args2.head)
762768
} && isSubArgs(args1.tail, args2.tail, tparams)
763769

764770
/** Test whether `tp1` has a base type of the form `B[T1, ..., Tn]` where

tests/pos/hkwild.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Test[T1](val x: T1) {
2+
def invert[El1, CC1[X]](implicit w1: T1 <:< CC1[El1]) = {
3+
val buf: CC1[_] = w1(x)
4+
???
5+
}
6+
}

0 commit comments

Comments
 (0)