Skip to content

Commit 5d1497d

Browse files
authored
Make singleton types subtypes of their refined type (#16135)
2 parents 9693bc7 + 935ac94 commit 5d1497d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
19541954
val info1 = m.info.widenExpr
19551955
isSubInfo(info1, tp2.refinedInfo.widenExpr, m.symbol.info.orElse(info1))
19561956
|| matchAbstractTypeMember(m.info)
1957+
|| (tp1.isStable && isSubType(TermRef(tp1, m.symbol), tp2.refinedInfo))
19571958

19581959
tp1.member(name) match // inlined hasAltWith for performance
19591960
case mbr: SingleDenotation => qualifies(mbr)

tests/pos/i10980.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class A:
2+
val x: AnyRef = Object()
3+
val y: AnyRef = Object()
4+
5+
@main def m: Unit =
6+
val a = new A
7+
val b: a.x.type = a.x
8+
val c: A { val x: a.x.type } = a
9+
val d: A { val x: a.x.type; val y: a.y.type } = a

0 commit comments

Comments
 (0)