Skip to content

Add missing case to TypeComparer #23550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
if tp2.isAny then true
else if compareCaptures(tp1, refs1, tp2, tp2.captureSet)
|| !ctx.mode.is(Mode.CheckBoundsOrSelfType) && tp1.isAlwaysPure
|| parent1.isSingleton && refs1.elems.forall(parent1 eq _)
then
val tp2a =
if tp1.isBoxedCapturing && !parent1.isBoxedCapturing
Expand Down
21 changes: 16 additions & 5 deletions tests/neg-custom-args/captures/i23207.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
| Required: A
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23207.scala:16:11 ---------------------------------------
16 | b.getBox.x // error
| ^^^^^^^^^^
| Found: (Box[(b : B^{io})^{b}]#x : (b : B^{io})^{b})
| Required: A^?
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23207.scala:18:13 ---------------------------------------
18 | val _: A = c // error
| ^
| Found: (c : B^{b})
| Required: A
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23207.scala:23:2 ----------------------------------------
23 | class B extends A: // error, now we see the error for the whole block since there are no nested errors
| ^
| Found: A^{io}
| Required: A
24 | val hide: AnyRef^{io} = io
25 | val b = new B
26 | val c = b.getBox.x
27 | c
|
| longer explanation available when compiling with `-explain`
14 changes: 13 additions & 1 deletion tests/neg-custom-args/captures/i23207.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ def leak(io: AnyRef^): A =
val b = new B
val box = b.getBox
val a: A = box.x // error
b.getBox.x // error
val c = b.getBox.x
val _: B^{b} = c // ok
val _: A = c // error
c // no error here since we don't propagate expected type into the last expression of a block
// and the whole block's span overlaps with previous errors

def leak2(io: AnyRef^): A =
class B extends A: // error, now we see the error for the whole block since there are no nested errors
val hide: AnyRef^{io} = io

val b = new B
val c = b.getBox.x
c
6 changes: 3 additions & 3 deletions tests/neg/no-patches.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
| ^^^^^^^^^^^^^^^^^^^^
| value 3.4 is not a member of object language
-- [E008] Not Found Error: tests/neg/no-patches.scala:4:36 -------------------------------------------------------------
4 |val _ = scala.language.experimental.captureChecking // error: we do not patch `scala.language.experimental`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| value captureChecking is not a member of object language.experimental
4 |val _ = scala.language.experimental.modularity // error: we do not patch `scala.language.experimental`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| value modularity is not a member of object language.experimental
-- [E008] Not Found Error: tests/neg/no-patches.scala:5:15 -------------------------------------------------------------
5 |val _ = Predef.summon[DummyImplicit] // error: we do not patch `scala.Predef`
| ^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/no-patches.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//> using options -Yno-stdlib-patches

val _ = scala.language.`3.4` // error: we do not patch `scala.language`
val _ = scala.language.experimental.captureChecking // error: we do not patch `scala.language.experimental`
val _ = scala.language.experimental.modularity // error: we do not patch `scala.language.experimental`
val _ = Predef.summon[DummyImplicit] // error: we do not patch `scala.Predef`
6 changes: 6 additions & 0 deletions tests/pos-custom-args/captures/singleton-conformance.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import language.experimental.captureChecking

def id[T](x: T): T = x

trait A:
def t(): this.type = id(this)
Loading