Skip to content

Commit 3dbf935

Browse files
committed
Generalize self-referential member comparisons.
The special case in hasMatchingMember dealing with self-refential members has to be generalized to deal lower and upper bounds. Test case is t762.scala
1 parent ba0b56e commit 3dbf935

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,11 +861,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
861861
// special case for situations like:
862862
// class C { type T }
863863
// val foo: C
864-
// foo.type <: C { type T = foo.T }
864+
// foo.type <: C { type T {= , <: , >:} foo.T }
865865
def selfReferentialMatch = tp1.isInstanceOf[SingletonType] && {
866866
rinfo2 match {
867-
case rinfo2: TypeAlias =>
868-
!defn.isBottomType(tp1.widen) && (tp1 select name) =:= rinfo2.alias
867+
case rinfo2: TypeBounds =>
868+
val mbr1 = tp1.select(name)
869+
!defn.isBottomType(tp1.widen) &&
870+
(mbr1 =:= rinfo2.hi || (rinfo2.hi ne rinfo2.lo) && mbr1 =:= rinfo2.lo)
869871
case _ => false
870872
}
871873
}

tests/pending/pos/t762.scala

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/pos/t762.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait Foo { type T }
2+
trait Bar1 extends Foo { val x : Foo { type T <: Bar1.this.T } = this }
3+
trait Bar2 extends Foo { val x : Foo { type T = Bar2.this.T } = this }
4+
trait Bar3 extends Foo { val x : Foo { type T >: Bar3.this.T } = this }

0 commit comments

Comments
 (0)