-
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.
Canonicalize capture variable subtype comparisons (#22299)
Fixes #22103 Subtype problems where at least one side is a type variable representing a capture variable are canonicalized to capturing type comparisons on the special `CapSet` for the universe capture sets. For example, `C <: CapSet^{C^}` becomes `CapSet^{C^} <: CapSet^{C^}`, and `A <: B` becomes `CapSet^{A^} <: CapSet^{B^}` if both `A` and `B` are capture variables. Supersedes #22183 and #22289. This solution is overall cleaner and does not require adding a new bit to the TypeComparer's ApproxState. TODOs/Issues/Questions: - [x] Fix extension method in test [cc-poly-varargs.scala](https://github.com/dotty-staging/dotty/blob/capture-subtyping-canon/tests/pos-custom-args/captures/cc-poly-varargs.scala). Currently causes an infinite regress. - [x] Fix the aftermath * tests/neg-custom-args/captures/lazylists-exceptions.scala * tests/neg-custom-args/captures/exceptions.scala * tests/neg-custom-args/captures/real-try.scala * tests/run-custom-args/captures/colltest5 - [x] Some negative cases in test [capture-vars-subtyping.scala](https://github.com/dotty-staging/dotty/blob/capture-subtyping-canon/tests/neg-custom-args/captures/capture-vars-subtyping.scala) pass: `D <: E` fails, but its canonicalized form `CapSet^{D^} <: CapSet^{E^}` now succeeds. Potential problem in the subcapturing implementation. - [x] ~Extend to intersection/unions `def f[C^, D^, E <: C | D, F <: C & D](...) = ...` etc.~ Lacking good uses cases, not planned right now. - [X] ~If we have `C^` declared in the current context, should there be a difference between `C` vs. `C^` for subsequent mentions? We currently do, but seems a bit too subtle for users.~ Will be addressed by a new scheme for declaring capture variables using context bounds.
- Loading branch information
Showing
5 changed files
with
82 additions
and
18 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
48 changes: 48 additions & 0 deletions
48
tests/neg-custom-args/captures/capture-vars-subtyping.scala
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,48 @@ | ||
import language.experimental.captureChecking | ||
import caps.* | ||
|
||
def test[C^] = | ||
val a: C = ??? | ||
val b: CapSet^{C^} = a | ||
val c: C = b | ||
val d: CapSet^{C^, c} = a | ||
|
||
// TODO: make "CapSet-ness" of type variables somehow contagious? | ||
// Then we don't have to spell out the bounds explicitly... | ||
def testTrans[C^, D >: CapSet <: C, E >: CapSet <: D, F >: C <: CapSet^] = | ||
val d1: D = ??? | ||
val d2: CapSet^{D^} = d1 | ||
val d3: D = d2 | ||
val e1: E = ??? | ||
val e2: CapSet^{E^} = e1 | ||
val e3: E = e2 | ||
val d4: D = e1 | ||
val c1: C = d1 | ||
val c2: C = e1 | ||
val f1: F = c1 | ||
val d_e_f1: CapSet^{D^,E^,F^} = d1 | ||
val d_e_f2: CapSet^{D^,E^,F^} = e1 | ||
val d_e_f3: CapSet^{D^,E^,F^} = f1 | ||
val f2: F = d_e_f1 | ||
val c3: C = d_e_f1 // error | ||
val c4: C = f1 // error | ||
val e4: E = f1 // error | ||
val e5: E = d1 // error | ||
val c5: CapSet^{C^} = e1 | ||
|
||
|
||
trait A[+T] | ||
|
||
trait B[-C] | ||
|
||
def testCong[C^, D^] = | ||
val a: A[C] = ??? | ||
val b: A[CapSet^{C^}] = a | ||
val c: A[CapSet^{D^}] = a // error | ||
val d: A[CapSet^{C^,D^}] = a | ||
val e: A[C] = d // error | ||
val f: B[C] = ??? | ||
val g: B[CapSet^{C^}] = f | ||
val h: B[C] = g | ||
val i: B[CapSet^{C^,D^}] = h // error | ||
val j: B[C] = i |
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