Skip to content

Commit fb66af2

Browse files
authored
Add missing case to TypeComparer (#23550)
We now have: x.type^{x} <: x.type
2 parents ce9fdfc + f93c18e commit fb66af2

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
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: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@
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^?
8+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23207.scala:18:13 ---------------------------------------
9+
18 | val _: A = c // error
10+
| ^
11+
| Found: (c : B^{b})
12+
| Required: A
13+
|
14+
| longer explanation available when compiling with `-explain`
15+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23207.scala:23:2 ----------------------------------------
16+
23 | class B extends A: // error, now we see the error for the whole block since there are no nested errors
17+
| ^
18+
| Found: A^{io}
19+
| Required: A
20+
24 | val hide: AnyRef^{io} = io
21+
25 | val b = new B
22+
26 | val c = b.getBox.x
23+
27 | c
1324
|
1425
| longer explanation available when compiling with `-explain`

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,16 @@ 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
17+
val _: B^{b} = c // ok
18+
val _: A = c // error
19+
c // no error here since we don't propagate expected type into the last expression of a block
20+
// and the whole block's span overlaps with previous errors
21+
22+
def leak2(io: AnyRef^): A =
23+
class B extends A: // error, now we see the error for the whole block since there are no nested errors
24+
val hide: AnyRef^{io} = io
25+
26+
val b = new B
27+
val c = b.getBox.x
28+
c

tests/neg/no-patches.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
| ^^^^^^^^^^^^^^^^^^^^
44
| value 3.4 is not a member of object language
55
-- [E008] Not Found Error: tests/neg/no-patches.scala:4:36 -------------------------------------------------------------
6-
4 |val _ = scala.language.experimental.captureChecking // error: we do not patch `scala.language.experimental`
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8-
| value captureChecking is not a member of object language.experimental
6+
4 |val _ = scala.language.experimental.modularity // error: we do not patch `scala.language.experimental`
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
| value modularity is not a member of object language.experimental
99
-- [E008] Not Found Error: tests/neg/no-patches.scala:5:15 -------------------------------------------------------------
1010
5 |val _ = Predef.summon[DummyImplicit] // error: we do not patch `scala.Predef`
1111
| ^^^^^^^^^^^^^

tests/neg/no-patches.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//> using options -Yno-stdlib-patches
22

33
val _ = scala.language.`3.4` // error: we do not patch `scala.language`
4-
val _ = scala.language.experimental.captureChecking // error: we do not patch `scala.language.experimental`
4+
val _ = scala.language.experimental.modularity // error: we do not patch `scala.language.experimental`
55
val _ = Predef.summon[DummyImplicit] // error: we do not patch `scala.Predef`
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)