Skip to content

Commit 2db1921

Browse files
committed
Add lazyvals test that started the problem
1 parent 2573b83 commit 2db1921

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:7:22 -------------------------------------
2+
7 | val _: () -> Unit = x // error
3+
| ^
4+
| Found: (C.this.x : () ->{C.this.io} Unit)
5+
| Required: () -> Unit
6+
|
7+
| Note that capability C.this.io is not included in capture set {}.
8+
|
9+
| longer explanation available when compiling with `-explain`
10+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:12:22 ------------------------------------
11+
12 | val _: () -> Unit = l1 // error
12+
| ^^
13+
| Found: (C.this.l1 : () ->{C.this.c.io} Unit)
14+
| Required: () -> Unit
15+
|
16+
| Note that capability C.this.c.io is not included in capture set {}.
17+
|
18+
| longer explanation available when compiling with `-explain`
19+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:16:22 ------------------------------------
20+
16 | val _: () -> Unit = l2 // error
21+
| ^^
22+
| Found: (C.this.l2 : () ->{C.this.io} Unit)
23+
| Required: () -> Unit
24+
|
25+
| Note that capability C.this.io is not included in capture set {}.
26+
|
27+
| longer explanation available when compiling with `-explain`
28+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:20:22 ------------------------------------
29+
20 | val _: () -> Unit = s1 // error
30+
| ^^
31+
| Found: (C.this.s1 : () ->{C.this.c.io} Unit)
32+
| Required: () -> Unit
33+
|
34+
| Note that capability C.this.c.io is not included in capture set {}.
35+
|
36+
| longer explanation available when compiling with `-explain`
37+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:24:22 ------------------------------------
38+
24 | val _: () -> Unit = s2 // error
39+
| ^^
40+
| Found: (C.this.s2 : () ->{C.this.io} Unit)
41+
| Required: () -> Unit
42+
|
43+
| Note that capability C.this.io is not included in capture set {}.
44+
|
45+
| longer explanation available when compiling with `-explain`
46+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:32:22 ------------------------------------
47+
32 | val _: () -> Unit = l11 // error
48+
| ^^^
49+
| Found: (C.this.l11 : () ->{C.this} Unit)
50+
| Required: () -> Unit
51+
|
52+
| Note that capability C.this is not included in capture set {}.
53+
|
54+
| longer explanation available when compiling with `-explain`
55+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:36:22 ------------------------------------
56+
36 | val _: () -> Unit = l12 // error
57+
| ^^^
58+
| Found: (C.this.l12 : () ->{C.this.io} Unit)
59+
| Required: () -> Unit
60+
|
61+
| Note that capability C.this.io is not included in capture set {}.
62+
|
63+
| longer explanation available when compiling with `-explain`
64+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:41:22 ------------------------------------
65+
41 | val _: () -> Unit = s11 // error
66+
| ^^^
67+
| Found: (C.this.s11 : () ->{C.this} Unit)
68+
| Required: () -> Unit
69+
|
70+
| Note that capability C.this is not included in capture set {}.
71+
|
72+
| longer explanation available when compiling with `-explain`
73+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:45:22 ------------------------------------
74+
45 | val _: () -> Unit = s12 // error
75+
| ^^^
76+
| Found: (C.this.s12 : () ->{C.this.io} Unit)
77+
| Required: () -> Unit
78+
|
79+
| Note that capability C.this.io is not included in capture set {}.
80+
|
81+
| longer explanation available when compiling with `-explain`
82+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:50:22 ------------------------------------
83+
50 | val _: () -> Unit = x // error
84+
| ^
85+
| Found: (x : () ->{io} Unit)
86+
| Required: () -> Unit
87+
|
88+
| Note that capability io is not included in capture set {}.
89+
|
90+
| longer explanation available when compiling with `-explain`
91+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazyvals6.scala:55:22 ------------------------------------
92+
55 | val _: () -> Unit = z // error
93+
| ^
94+
| Found: (z : () ->{c.io} Unit)
95+
| Required: () -> Unit
96+
|
97+
| Note that capability c.io is not included in capture set {}.
98+
|
99+
| longer explanation available when compiling with `-explain`
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class IO extends caps.SharedCapability:
2+
def write(): Unit = ()
3+
4+
class C(val io: IO):
5+
lazy val x = () => io.write()
6+
val y: () ->{io} Unit = x
7+
val _: () -> Unit = x // error
8+
9+
val c = C(io)
10+
lazy val l1 = () => c.io.write()
11+
val _: () ->{c.io} Unit = l1
12+
val _: () -> Unit = l1 // error
13+
14+
lazy val l2 = () => this.io.write()
15+
val _: () ->{this.io} Unit = l2
16+
val _: () -> Unit = l2 // error
17+
18+
val s1 = () => c.io.write()
19+
val _: () ->{c.io} Unit = s1
20+
val _: () -> Unit = s1 // error
21+
22+
val s2 = () => this.io.write()
23+
val _: () ->{this.io} Unit = s2
24+
val _: () -> Unit = s2 // error
25+
26+
lazy val d = C(io)
27+
lazy val l11 = () => d.io.write()
28+
val _: () ->{this} Unit = l11
29+
// it's just `this`, not `this.d`, since we also have to account for the fact
30+
// that `d` might be initialized here, so we have to charge its call captures
31+
// which are approximated by `this`.
32+
val _: () -> Unit = l11 // error
33+
34+
lazy val l12 = () => this.io.write()
35+
val _: () ->{this.io} Unit = l12
36+
val _: () -> Unit = l12 // error
37+
38+
val s11 = () => d.io.write()
39+
val _: () ->{this} Unit = s11
40+
// just `this`` not `this.d`, same reason as above
41+
val _: () -> Unit = s11 // error
42+
43+
val s12 = () => this.io.write()
44+
val _: () ->{this.io} Unit = s1
45+
val _: () -> Unit = s12 // error
46+
47+
def test(io: IO) =
48+
lazy val x = () => io.write()
49+
val y: () ->{io} Unit = x
50+
val _: () -> Unit = x // error
51+
52+
val c = C(io)
53+
lazy val z = () => c.io.write()
54+
val _: () -> {c.io} Unit = z
55+
val _: () -> Unit = z // error
56+

0 commit comments

Comments
 (0)