Skip to content

Commit 7f811dd

Browse files
committed
Add missing case to TypeComparer
We now have: x.type^{x} <: x.type
1 parent 7987a0c commit 7f811dd

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
547547
if tp2.isAny then true
548548
else if compareCaptures(tp1, refs1, tp2, tp2.captureSet)
549549
|| !ctx.mode.is(Mode.CheckBoundsOrSelfType) && tp1.isAlwaysPure
550+
|| parent1.isSingleton && refs1.elems.forall(parent1 eq _)
550551
then
551552
val tp2a =
552553
if tp1.isBoxedCapturing && !parent1.isBoxedCapturing

tests/neg-custom-args/captures/i23207.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ def leak(io: AnyRef^): A =
1313
val b = new B
1414
val box = b.getBox
1515
val a: A = box.x // error
16-
b.getBox.x // error
16+
val c = b.getBox.x // now OK
17+
val _: B^{b} = c
18+
c
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import language.experimental.captureChecking
2+
3+
def id[T](x: T): T = x
4+
5+
trait A:
6+
def t(): this.type = id(this)

0 commit comments

Comments
 (0)