Skip to content

Commit e4a9f06

Browse files
committed
Add missing case to TypeComparer
We now have: x.type^{x} <: x.type
1 parent ce98496 commit e4a9f06

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
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.check

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,3 @@
55
| Required: A
66
|
77
| longer explanation available when compiling with `-explain`
8-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23207.scala:16:11 ---------------------------------------
9-
16 | b.getBox.x // error
10-
| ^^^^^^^^^^
11-
| Found: (Box[(b : B^{io})^{b}]#x : (b : B^{io})^{b})
12-
| Required: A^?
13-
|
14-
| longer explanation available when compiling with `-explain`

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)