-
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
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.
- Loading branch information
Showing
3 changed files
with
88 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
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
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 | ||
|
||
|
||
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