Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2610,10 +2610,12 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
case tp1: TypeVar if tp1.isInstantiated =>
tp1.underlying & tp2
case CapturingType(parent1, refs1) =>
if subCaptures(tp2.captureSet, refs1, frozen = true).isOK
val refs2 = tp2.captureSet
if subCaptures(refs2, refs1, frozen = true).isOK
&& tp1.isBoxedCapturing == tp2.isBoxedCapturing
then
parent1 & tp2
if refs2.isAlwaysEmpty then parent1 & tp2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should roll the isAlwaysEmpty optimization into capturing?

else (parent1 & tp2).capturing(refs2)
else
tp1.derivedCapturingType(parent1 & tp2, refs1)
case tp1: AnnotatedType if !tp1.isRefining =>
Expand Down
7 changes: 7 additions & 0 deletions tests/neg-custom-args/captures/cc-glb.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/cc-glb.scala:7:19 ----------------------------------------
7 | val x2: Foo[T] = x1 // error
| ^^
| Found: (x1 : (Foo[T]^) & (Foo[Any]^{io}))
| Required: Foo[T]
|
| longer explanation available when compiling with `-explain`
8 changes: 8 additions & 0 deletions tests/neg-custom-args/captures/cc-glb.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import language.experimental.captureChecking
trait Cap
trait Foo[+T]

def magic[T](io: Cap^, x: Foo[T]^{io}): Foo[T]^{} =
val x1: Foo[T]^{cap} & Foo[Any]^{io} = x
val x2: Foo[T] = x1 // error
x2 // boom, an impure value becomes pure