From 1eee2e0ee20a9b31906746d8a3ca11720bf0a6ae Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 3 Oct 2022 14:36:54 +0200 Subject: [PATCH] Fix #10980 --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 4 +++- tests/pos/i10980.scala | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i10980.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 9e946f430edc..595f5e32eb97 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1955,9 +1955,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling isSubInfo(info1, tp2.refinedInfo.widenExpr, m.symbol.info.orElse(info1)) || matchAbstractTypeMember(m.info) - tp1.member(name) match // inlined hasAltWith for performance + def memberQualifies = tp1.member(name) match // inlined hasAltWith for performance case mbr: SingleDenotation => qualifies(mbr) case mbr => mbr hasAltWith qualifies + + memberQualifies || (tp1.isStable && isSub(TermRef(tp1, name), tp2.refinedInfo)) } final def ensureStableSingleton(tp: Type): SingletonType = tp.stripTypeVar match { 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