Skip to content

Commit 7664e9d

Browse files
committed
Fix isSubArg
Strange as it sounds, a TypeBounds can be a subtype of a single type.
1 parent 0b252fa commit 7664e9d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -925,10 +925,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
925925
case tycon2: TypeRef =>
926926
isMatchingApply(tp1) || {
927927
tycon2.info match {
928-
case tycon2: TypeBounds =>
929-
compareLower(tycon2, tyconIsTypeRef = true)
930-
case tycon2: ClassInfo =>
931-
val base = tp1.baseType(tycon2.cls)
928+
case info2: TypeBounds =>
929+
compareLower(info2, tyconIsTypeRef = true)
930+
case info2: ClassInfo =>
931+
val base = tp1.baseType(info2.cls)
932932
if (base.exists && base.ne(tp1)) isSubType(base, tp2)
933933
else fourthTry(tp1, tp2)
934934
case _ =>
@@ -976,8 +976,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
976976
case tp2: TypeBounds =>
977977
tp2.contains(tp1)
978978
case _ =>
979-
(v > 0 || isSubType(tp2, tp1)) &&
980-
(v < 0 || isSubType(tp1, tp2))
979+
tp1 match {
980+
case TypeBounds(lo1, hi1) =>
981+
hi1 <:< tp2 && tp2 <:< lo1 // this can succeed in case tp2 bounds are bad
982+
case _ =>
983+
(v > 0 || isSubType(tp2, tp1)) &&
984+
(v < 0 || isSubType(tp1, tp2))
985+
}
981986
}
982987
isSub(args1.head, args2.head)
983988
} && isSubArgs(args1.tail, args2.tail, tparams.tail)

0 commit comments

Comments
 (0)