-
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.
Treat by-name closures specially in recheck
A by-name Closure node, which is produced by phase ElimByName gets a target type to indicate it's a contextual zero parameter closure. But for the purposes of rechecking and capture checking, it needs to be treated like a function. In particular the type of the closure needs to be derived from the result type of the anonymous function. Fixes #21920
- Loading branch information
Showing
5 changed files
with
55 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21920.scala:34:34 --------------------------------------- | ||
34 | val cell: Cell[File] = File.open(f => Cell(Seq(f))) // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Found: Cell[box File^{f, f²}]{val head: () ?->? IterableOnce[box File^{f, f²}]^?}^? | ||
| Required: Cell[File] | ||
| | ||
| where: f is a reference to a value parameter | ||
| f² is a reference to a value parameter | ||
| | ||
| 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import language.experimental.captureChecking | ||
|
||
trait Iterator[+A] extends IterableOnce[A]: | ||
self: Iterator[A]^ => | ||
def next(): A | ||
|
||
trait IterableOnce[+A] extends Any: | ||
def iterator: Iterator[A]^{this} | ||
|
||
final class Cell[A](head: => IterableOnce[A]^): | ||
def headIterator: Iterator[A]^{this} = head.iterator | ||
|
||
class File private (): | ||
private var closed = false | ||
|
||
def close() = closed = true | ||
|
||
def read() = | ||
assert(!closed, "File closed") | ||
1 | ||
|
||
object File: | ||
def open[T](f: File^ => T): T = | ||
val file = File() | ||
try | ||
f(file) | ||
finally | ||
file.close() | ||
|
||
object Seq: | ||
def apply[A](xs: A*): IterableOnce[A] = ??? | ||
|
||
@main def Main() = | ||
val cell: Cell[File] = File.open(f => Cell(Seq(f))) // error | ||
val file = cell.headIterator.next() | ||
file.read() |