File tree Expand file tree Collapse file tree 2 files changed +72
-11
lines changed
tests/neg-custom-args/captures Expand file tree Collapse file tree 2 files changed +72
-11
lines changed Original file line number Diff line number Diff line change
1
+ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:18:2 ----------------------------------------
2
+ 18 | () => // error
3
+ | ^
4
+ | Found: {x} () -> Int
5
+ | Required: () -> Int
6
+ 19 | val c : {x} C = new C(x)
7
+ 20 | val boxed1 : (({*} C) => Unit) -> Unit = box1(c)
8
+ 21 | boxed1((cap: {*} C) => unsafe(c))
9
+ 22 | 0
10
+ |
11
+ | longer explanation available when compiling with `-explain`
12
+ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:25:2 ----------------------------------------
13
+ 25 | () => // error
14
+ | ^
15
+ | Found: {x} () -> Int
16
+ | Required: () -> Int
17
+ 26 | val c : {x} C = new C(x)
18
+ 27 | val boxed2 : Observe[{*} C] = box2(c)
19
+ 28 | boxed2((cap: {*} C) => unsafe(c))
20
+ 29 | 0
21
+ |
22
+ | longer explanation available when compiling with `-explain`
23
+ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:33:37 ---------------------------------------
24
+ 33 | val boxed2 : Observe[{*} C] = box2(c) // error
25
+ | ^
26
+ | Found: {*} C
27
+ | Required: box {*} C{arg: ? C}
28
+ |
29
+ | longer explanation available when compiling with `-explain`
30
+ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:44:2 ----------------------------------------
31
+ 44 | x: (() -> Unit) // error
32
+ | ^
33
+ | Found: (x : {sayHello, io} () -> Unit)
34
+ | Required: () -> Unit
35
+ |
36
+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change 1
- class C {
2
- def bad () = println(" I've gone bad!" )
3
- }
4
-
5
- def newC : {* } C = C ()
6
-
7
1
type Observe [T ] = (T => Unit ) -> Unit
2
+
8
3
def unsafe (cap : {* } C ) = cap.bad()
9
4
10
- def box [T ](v : T ) : Observe [ T ] = {
5
+ def box1 [T ](v : T ) : ( T => Unit ) -> Unit = {
11
6
(fn : T => Unit ) => fn(v)
12
7
}
13
8
14
- def main ( ) : Int = {
15
- val boxed : Observe [{ * } C ] = box(newC) // error
16
- boxed(unsafe)
9
+ def box2 [ T ]( v : T ) : Observe [ T ] = {
10
+ ( fn : T => Unit ) => fn(v)
11
+ }
17
12
18
- 0
13
+ class C (val arg : {* } C ) {
14
+ def bad () = println(" I've gone bad!" )
19
15
}
16
+
17
+ def main1 (x : {* } C ) : () -> Int =
18
+ () => // error
19
+ val c : {x} C = new C (x)
20
+ val boxed1 : (({* } C ) => Unit ) -> Unit = box1(c)
21
+ boxed1((cap : {* } C ) => unsafe(c))
22
+ 0
23
+
24
+ def main2 (x : {* } C ) : () -> Int =
25
+ () => // error
26
+ val c : {x} C = new C (x)
27
+ val boxed2 : Observe [{* } C ] = box2(c)
28
+ boxed2((cap : {* } C ) => unsafe(c))
29
+ 0
30
+
31
+ def main3 (x : {* } C ) =
32
+ def c : {* } C = new C (x)
33
+ val boxed2 : Observe [{* } C ] = box2(c) // error
34
+ boxed2((cap : {* } C ) => unsafe(c))
35
+ 0
36
+
37
+ trait File :
38
+ def write (s : String ): Unit
39
+
40
+ def main (io : {* } Any ) =
41
+ val sayHello : (({io} File ) => Unit ) = (file : {io} File ) => file.write(" Hello World!\r\n " )
42
+ val filesList : List [{io} File ] = ???
43
+ val x = () => filesList.foreach(sayHello)
44
+ x : (() -> Unit ) // error
You can’t perform that action at this time.
0 commit comments