-
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.
The following two rules replace #13657: 1. Exploit capture monotonicity in the apply rule, as discussed in #14387. 2. A rule to make typing nested classes more flexible as discussed in #14390. There's also a bug fix where we now enforce a previously missing subcapturing relationship between the capture set of parent of a class and the capture set of the class itself. Clearly a class captures all variables captured by one of its parent classes.
- Loading branch information
Showing
11 changed files
with
198 additions
and
66 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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylists1.scala:25:63 ----------------------------------- | ||
25 | def concat(other: {f} LazyList[A]): {this} LazyList[A] = ??? : ({xs, f} LazyList[A]) // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Found: {xs, f} LazyList[A] | ||
| Required: {Mapped.this, xs} LazyList[A] | ||
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylists1.scala:25:66 ----------------------------------- | ||
25 | def concat(other: {f} LazyList[A]): {this, f} LazyList[A] = ??? : ({xs, f} LazyList[A]) // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Found: {xs, f} LazyList[A] | ||
| Required: {Mapped.this, f} LazyList[A] | ||
|
||
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
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,68 @@ | ||
import language.experimental.saferExceptions | ||
import annotation.unchecked.uncheckedVariance | ||
|
||
trait LazyList[+A]: | ||
this: {*} LazyList[A] => | ||
|
||
def isEmpty: Boolean | ||
def head: A | ||
def tail: {this} LazyList[A] | ||
|
||
object LazyNil extends LazyList[Nothing]: | ||
def isEmpty: Boolean = true | ||
def head = ??? | ||
def tail = ??? | ||
|
||
final class LazyCons[+T](val x: T, val xs: () => {*} LazyList[T]) extends LazyList[T]: | ||
this: {*} LazyList[T] => | ||
|
||
var forced = false | ||
var cache: {this} LazyList[T @uncheckedVariance] = compiletime.uninitialized | ||
|
||
private def force = | ||
if !forced then | ||
cache = xs() | ||
forced = true | ||
cache | ||
|
||
def isEmpty = false | ||
def head = x | ||
def tail: {this} LazyList[T] = force | ||
end LazyCons | ||
|
||
extension [A](xs: {*} LazyList[A]) | ||
def map[B](f: A => B): {xs, f} LazyList[B] = | ||
if xs.isEmpty then LazyNil | ||
else LazyCons(f(xs.head), () => xs.tail.map(f)) | ||
|
||
def filter(p: A => Boolean): {xs, p} LazyList[A] = | ||
if xs.isEmpty then LazyNil | ||
else if p(xs.head) then LazyCons(xs.head, () => xs.tail.filter(p)) | ||
else xs.tail.filter(p) | ||
|
||
def concat(ys: {*} LazyList[A]): {xs, ys} LazyList[A] = | ||
if xs.isEmpty then ys | ||
else LazyCons(xs.head, () => xs.tail.concat(ys)) | ||
end extension | ||
|
||
class Ex1 extends Exception | ||
class Ex2 extends Exception | ||
|
||
def test(using cap1: CanThrow[Ex1], cap2: CanThrow[Ex2]) = | ||
val xs = LazyCons(1, () => LazyNil) | ||
|
||
def f(x: Int): Int throws Ex1 = | ||
if x < 0 then throw Ex1() | ||
x * x | ||
|
||
def g(x: Int): Int throws Ex1 = | ||
if x < 0 then throw Ex1() | ||
x * x | ||
|
||
def x1 = xs.map(f) | ||
def x1c: {cap1} LazyList[Int] = x1 | ||
|
||
def x2 = x1.concat(xs.map(g).filter(_ > 0)) | ||
def x2c: {cap1, cap2} LazyList[Int] = x2 | ||
|
||
|
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
Oops, something went wrong.