Skip to content

Commit 4f934ad

Browse files
Use derivesFrom instead of isSubType for classes
`Some isSubType List` returns `false`, so use derivesFrom instead.
1 parent c3d23fe commit 4f934ad

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,11 +1905,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
19051905
case (tp1: ConstantType, tp2: ConstantType) =>
19061906
tp1 == tp2
19071907
case (tp1: TypeRef, tp2: TypeRef) if tp1.symbol.isClass && tp2.symbol.isClass =>
1908-
if (isSubType(tp1, tp2) || isSubType(tp2, tp1)) {
1908+
val cls1 = tp1.classSymbol
1909+
val cls2 = tp2.classSymbol
1910+
if (cls1.derivesFrom(cls2) || cls2.derivesFrom(cls1)) {
19091911
true
19101912
} else {
1911-
val cls1 = tp1.classSymbol
1912-
val cls2 = tp2.classSymbol
19131913
if (cls1.is(Final) || cls2.is(Final))
19141914
// One of these types is final and they are not mutually
19151915
// subtype, so they must be unrelated.

tests/neg/matchtype-seq.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,13 @@ object Test {
143143
identity[TD[Box2_C[Int, Int, Int]]](1)
144144
identity[TD[Box2_C[Int, Int, String]]]("") // error
145145
}
146+
147+
object Test2 {
148+
type M[A] = A match {
149+
case Option[Int] => String
150+
case Some[_] => Int
151+
}
152+
153+
def a[A]: M[Some[A]] = 1 // error
154+
def b[A]: M[Some[A]] = "" // error
155+
}

0 commit comments

Comments
 (0)