Skip to content

Commit d47b5fe

Browse files
committed
Fix subtyping to match DOT rule TDECL-<:
1 parent e0b290c commit d47b5fe

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,12 @@ class TypeComparer(initctx: Context) extends DotClass {
736736
def fourthTry(tp1: Type, tp2: Type): Boolean = tp1 match {
737737
case tp1: TypeRef =>
738738
tp1.info match {
739-
case TypeBounds(lo1, hi1) =>
740-
isSubType(hi1, tp2)
739+
case TypeBounds(lo1, hi1) => tp2 match {
740+
case tp2: NamedType if tp1.name == tp2.name =>
741+
isSubType(tp1.info, tp2.info)
742+
case _ =>
743+
isSubType(hi1, tp2)
744+
}
741745
case _ =>
742746
(tp1.symbol eq NothingClass) && tp2.isInstanceOf[ValueType] ||
743747
(tp1.symbol eq NullClass) && tp2.dealias.typeSymbol.isNullableClass

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class tests extends CompilerTest {
5252
@Test def pos_approximateUnion = compileFile(posDir, "approximateUnion", doErase)
5353
@Test def pos_tailcall = compileDir(posDir + "tailcall/", doErase)
5454
@Test def pos_nullarify = compileFile(posDir, "nullarify", "-Ycheck:nullarify" :: doErase)
55+
@Test def pos_subtyping = compileFile(posDir, "subtyping", doErase)
5556

5657
@Test def pos_all = compileFiles(posDir, twice)
5758
@Test def new_all = compileFiles(newDir, twice)

tests/pos/subtyping.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class C1
2+
class C2 extends C1
3+
class C3 extends C2
4+
class C4 extends C3
5+
6+
object Test {
7+
// Test DOT rule TDECL-<:
8+
def test_typebounds(): Unit = {
9+
val c31 : { type T >: C3 <: C1 } = ???
10+
val c41 : { type T >: C4 <: C1 } = ???
11+
val c42 : { type T >: C4 <: C2 } = ???
12+
implicitly[c31.T <:< c41.T]
13+
implicitly[c42.T <:< c41.T]
14+
}
15+
}

0 commit comments

Comments
 (0)