-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) Intuitively, `glb(S1^C1, S2^C2)` should capture `C1 ⊓ C2`, where `⊓` denotes the glb of capture sets. When computing `glb(tp1, tp2)`, if `tp1` matches `CapturingType(parent1, refs1)`, it captures `C0 ++ refs1` where `C0` is the nested capture sets inside `parent1`. Denote the capture set of `tp2` with `C2`, the result should capture `(C0 ++ refs1) ⊓ C2`. Presumably, `⊓` distributes over the union (`++`); therefore `(C0 ++ refs1) ⊓ C2` equals `C0 ⊓ C2 ++ refs1 ⊓ C2`. Previously, if `C2` is a subcapture of `refs1`, it is simply dropped. However, based on the above reasoning, we have `refs1 ⊓ C2` equals `C2`; therefore `C0 ⊓ C2 ++ refs1 ⊓ C2` equals `C0 ⊓ C2 ++ C2`. `C2` should not be dropped, but rather kept. This PR fixes the logic to behave correctly. Fixes #18246.
- Loading branch information
Showing
4 changed files
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |