-
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
178 additions
and
65 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,49 @@ | ||
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 | ||
|
||
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)) | ||
|
||
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 | ||
|
||
val res = xs.map(f) | ||
res: {cap1} LazyList[Int] | ||
|
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