-
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.
Disallow covariant
cap
s in the lower bound of type members (#19624)
Fixes #19330. Since when instantiating a type member we do not disallow covariant `cap`s in the instance, a check is added at the application site to check for covariant `cap`s in the lower bound of type members to maintain soundness. This check is elided for type parameters since their instances are always checked at the instantiation site.
- Loading branch information
Showing
4 changed files
with
55 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import language.experimental.captureChecking | ||
|
||
trait Logger | ||
def usingLogger[T](op: Logger^ => T): T = ??? | ||
|
||
def foo[T >: () => Logger^](): T = | ||
val leaked = usingLogger[T]: l => // ok | ||
val t: () => Logger^ = () => l | ||
t: T | ||
leaked | ||
|
||
def test(): Unit = | ||
val bad: () => Logger^ = foo[() => Logger^] // error | ||
val leaked: Logger^ = bad() // leaked scoped capability! |
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,13 @@ | ||
import language.experimental.captureChecking | ||
|
||
trait Logger | ||
def usingLogger[T](op: Logger^ => T): T = ??? | ||
|
||
trait Foo: | ||
type T >: () => Logger^ | ||
|
||
def foo: this.T = | ||
val leaked = usingLogger[T]: l => // error | ||
val t: () => Logger^ = () => l | ||
t: T | ||
leaked |
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,21 @@ | ||
import language.experimental.captureChecking | ||
|
||
trait Logger | ||
def usingLogger[T](op: Logger^ => T): T = ??? | ||
|
||
trait Foo: | ||
type T >: () => Logger^ | ||
|
||
class Bar extends Foo: | ||
type T = () => Logger^ | ||
|
||
def foo(x: Foo): x.T = | ||
val leaked = usingLogger[x.T]: l => // error | ||
val t: () => Logger^ = () => l | ||
t: x.T | ||
leaked | ||
|
||
def test(): Unit = | ||
val bar = new Bar | ||
val bad: bar.T = foo(bar) | ||
val leaked: Logger^ = bad() // leaked scoped capability! |