diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 9e946f430edc..9365bafd8282 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1954,6 +1954,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling val info1 = m.info.widenExpr isSubInfo(info1, tp2.refinedInfo.widenExpr, m.symbol.info.orElse(info1)) || matchAbstractTypeMember(m.info) + || (tp1.isStable && isSubType(TermRef(tp1, m.symbol), tp2.refinedInfo)) tp1.member(name) match // inlined hasAltWith for performance case mbr: SingleDenotation => qualifies(mbr) diff --git a/tests/pos/i10980.scala b/tests/pos/i10980.scala new file mode 100644 index 000000000000..7d951322463b --- /dev/null +++ b/tests/pos/i10980.scala @@ -0,0 +1,9 @@ +class A: + val x: AnyRef = Object() + val y: AnyRef = Object() + +@main def m: Unit = + val a = new A + val b: a.x.type = a.x + val c: A { val x: a.x.type } = a + val d: A { val x: a.x.type; val y: a.y.type } = a