Skip to content

Commit 114c8f0

Browse files
committed
Tweaks to tests and doc
1 parent bd8136d commit 114c8f0

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

docs/_docs/reference/experimental/cc.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@ Generally, the string following the capture set consists of alternating numbers
705705
- `F` : a variable resulting from _filtering_ the elements of the variable indicated by the string to the right,
706706
- `I` : a variable resulting from an _intersection_ of two capture sets,
707707
- `D` : a variable resulting from the set _difference_ of two capture sets.
708+
- `R` : a regular variable that _refines_ a class parameter, so that the capture
709+
set of a constructor argument is known in the class instance type.
708710

709711
At the end of a compilation run, `-Ycc-debug` will print all variable dependencies of variables referred to in previous output. Here is an example:
710712
```
@@ -723,3 +725,5 @@ This section lists all variables that appeared in previous diagnostics and their
723725
- variable `31` has a constant fixed superset `{xs, f}`
724726
- variable `32` has no dependencies.
725727

728+
729+

tests/neg-custom-args/captures/refs.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import java.io.*
22

3+
type Proc = () => Unit
4+
35
class Ref[T](init: T):
46
var x: T = init
57
def setX(x: T): Unit = this.x = x
68

9+
class MonoRef(init: Proc):
10+
type MonoProc = Proc
11+
var x: MonoProc = init
12+
def setX(x: MonoProc): Unit = this.x = x
13+
714
def usingLogFile[T](op: (local: caps.Root) ?-> FileOutputStream^{local} => T): T =
815
val logFile = FileOutputStream("log")
916
val result = op(logFile)
1017
logFile.close()
1118
result
1219

13-
type Proc = () => Unit
1420
def test1 =
1521
usingLogFile[Proc]: (local: caps.Root) ?=> // error (but with a hard to parse error message)
1622
(f: FileOutputStream^{local}) =>
@@ -19,19 +25,25 @@ def test1 =
1925

2026
def test2 =
2127
val r = new Ref[Proc](() => ())
22-
usingLogFile[Unit]: f =>
28+
usingLogFile: f =>
2329
r.setX(() => f.write(10)) // error
2430
r.x() // crash: f is closed at that point
31+
val mr = new MonoRef(() => ())
32+
usingLogFile[Unit]: f =>
33+
mr.setX(() => f.write(10)) // error
2534

2635
def test3 =
2736
val r = new Ref[Proc](() => ())
28-
usingLogFile[Unit]: f =>
37+
usingLogFile[Unit]: f =>
2938
r.x = () => f.write(10) // error
3039
r.x() // crash: f is closed at that point
40+
val mr = MonoRef(() => ())
41+
usingLogFile: f =>
42+
mr.x = () => f.write(10) // error
3143

3244
def test4 =
3345
var r: Proc = () => ()
34-
usingLogFile[Unit]: f =>
46+
usingLogFile[Unit]: f =>
3547
r = () => f.write(10) // error
3648
r() // crash: f is closed at that point
3749

tests/neg-custom-args/captures/usingLogFile.check

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
| Required: Test2.Cell[() ->{cap[<root>]} Unit]
1111
|
1212
| longer explanation available when compiling with `-explain`
13-
-- Error: tests/neg-custom-args/captures/usingLogFile.scala:12:6 -------------------------------------------------------
14-
12 | val later = usingLogFile { f => () => f.write(0) } // error
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16-
| Non-local value later cannot have an inferred type
17-
| () ->{x$0, 'cap[..<root>](from instantiating usingLogFile)} Unit
18-
| with non-empty capture set {x$0, 'cap[..<root>](from instantiating usingLogFile)}.
19-
| The type needs to be declared explicitly.
2013
-- Error: tests/neg-custom-args/captures/usingLogFile.scala:23:14 ------------------------------------------------------
2114
23 | val later = usingLogFile { f => () => f.write(0) } // error
2215
| ^^^^^^^^^^^^

tests/neg-custom-args/captures/usingLogFile.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object Test1:
99
logFile.close()
1010
result
1111

12-
val later = usingLogFile { f => () => f.write(0) } // error
12+
private val later = usingLogFile { f => () => f.write(0) } // OK, `f` has global lifetime
1313
later()
1414

1515
object Test2:
@@ -62,7 +62,6 @@ object Test4:
6262
val later = usingFile("out", f => (y: Int) => xs.foreach(x => f.write(x + y))) // error
6363
later(1)
6464

65-
6665
def usingLogger[T](f: OutputStream^, op: (local: caps.Root) ?-> Logger^{f} => T): T =
6766
val logger = Logger(f)
6867
op(logger)

0 commit comments

Comments
 (0)