Skip to content

Commit dfe28e4

Browse files
committed
Test case 15772
1 parent 3e2d6aa commit dfe28e4

File tree

2 files changed

+72
-11
lines changed

2 files changed

+72
-11
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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`
Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
1-
class C {
2-
def bad() = println("I've gone bad!")
3-
}
4-
5-
def newC: {*} C = C()
6-
71
type Observe[T] = (T => Unit) -> Unit
2+
83
def unsafe(cap: {*} C) = cap.bad()
94

10-
def box[T](v: T) : Observe[T] = {
5+
def box1[T](v: T) : (T => Unit) -> Unit = {
116
(fn: T => Unit) => fn(v)
127
}
138

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+
}
1712

18-
0
13+
class C(val arg: {*} C) {
14+
def bad() = println("I've gone bad!")
1915
}
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

0 commit comments

Comments
 (0)