File tree 1 file changed +42
-0
lines changed
tests/neg-custom-args/captures
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*
2
+
3
+ class Ref [T ](init : T ):
4
+ var x : T = init
5
+ def setX (x : T ): Unit = this .x = x
6
+
7
+ def usingLogFile [sealed T ](op : FileOutputStream ^ => T ): T =
8
+ val logFile = FileOutputStream (" log" )
9
+ val result = op(logFile)
10
+ logFile.close()
11
+ result
12
+
13
+ type Proc = () => Unit
14
+ def test1 =
15
+ usingLogFile[Proc ]: f => // error
16
+ () =>
17
+ f.write(1 )
18
+ ()
19
+
20
+ def test2 =
21
+ val r = new Ref [Proc ](() => ())
22
+ usingLogFile[Unit ]: f =>
23
+ r.setX(() => f.write(10 )) // should be error
24
+ r.x() // crash: f is closed at that point
25
+
26
+ def test3 =
27
+ val r = new Ref [Proc ](() => ())
28
+ usingLogFile[Unit ]: f =>
29
+ r.x = () => f.write(10 ) // should be error
30
+ r.x() // crash: f is closed at that point
31
+
32
+ def test4 =
33
+ var r : Proc = () => () // error
34
+ usingLogFile[Unit ]: f =>
35
+ r = () => f.write(10 )
36
+ r() // crash: f is closed at that point
37
+
38
+
39
+
40
+
41
+
42
+
You can’t perform that action at this time.
0 commit comments