Skip to content

Commit e358c96

Browse files
committed
Record capturedVars also for global symbols
1 parent e6644b5 commit e358c96

File tree

8 files changed

+16
-29
lines changed

8 files changed

+16
-29
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,9 @@ class CheckCaptures extends Recheck, SymTransformer:
465465
catch case ex: IllegalCaptureRef =>
466466
report.error(em"Illegal capture reference: ${ex.getMessage}", sym.srcPos)
467467
CaptureSet.empty
468-
case _ =>
469-
if sym.isTerm || !sym.owner.isStaticOwner || sym.is(Lazy)
470-
then CaptureSet.Var(sym, nestedOK = false)
471-
else CaptureSet.empty)
468+
case _ if sym.is(Package) => CaptureSet.empty
469+
case _ => CaptureSet.Var(sym, nestedOK = false)
470+
)
472471

473472
// ---- Record Uses with MarkFree ----------------------------------------------------
474473

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| Capability cap outlives its scope: it leaks into outer capture set 's1 which is owned by value local.
66
| The leakage occurred when trying to match the following types:
77
|
8-
| Found: scala.util.boundary.Label[Object^'s1]
8+
| Found: scala.util.boundary.Label[Object^'s1]^'s2
99
| Required: scala.util.boundary.Label[Object^]^²
1010
|
1111
| where: ^ and cap refer to the universal root capability

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:52:27 --------------------------------------
3333
52 | val id: Id[Proc, Proc] = new Id[Proc, () -> Unit] // error
3434
| ^^^^^^^^^^^^^^^^^^^^^^^^
35-
| Found: Id[() => Unit, () -> Unit]
35+
| Found: Id[() => Unit, () -> Unit]^'s3
3636
| Required: Id[() =>² Unit, () =>³ Unit]
3737
|
3838
| Note that capability cap is not included in capture set {cap²}
@@ -46,7 +46,7 @@
4646
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:57:27 --------------------------------------
4747
57 | val id: File^ -> File^ = x => x // error
4848
| ^^^^^^
49-
| Found: (x: File^) ->'s3 File^²
49+
| Found: (x: File^) ->'s4 File^²
5050
| Required: File^ -> File^³
5151
|
5252
| Note that capability cap is not included in capture set {cap²}
@@ -71,8 +71,8 @@
7171
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:85:10 --------------------------------------
7272
85 | ps.map((x, y) => compose1(x, y)) // error
7373
| ^^^^^^^^^^^^^^^^^^^^^^^
74-
|Found: (x$1: (A^ ->'s4 A^'s5, A^ ->'s6 A^'s7)^'s8) ->'s9 A^'s10 ->'s11 A^'s12
75-
|Required: ((A ->{ps*} A, A ->{ps*} A)) => A^'s13 ->'s14 A^'s15
74+
|Found: (x$1: (A^ ->'s5 A^'s6, A^ ->'s7 A^'s8)^'s9) ->'s10 A^'s11 ->'s12 A^'s13
75+
|Required: ((A ->{ps*} A, A ->{ps*} A)) => A^'s14 ->'s15 A^'s16
7676
|
7777
|Note that capability ps* cannot be included in capture set {} of value x.
7878
|
@@ -83,8 +83,8 @@
8383
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:88:10 --------------------------------------
8484
88 | ps.map((x, y) => compose1(x, y)) // error
8585
| ^^^^^^^^^^^^^^^^^^^^^^^
86-
|Found: (x$1: (A^ ->'s16 A^'s17, A^ ->'s18 A^'s19)^'s20) ->'s21 A^'s22 ->'s23 A^'s24
87-
|Required: ((A ->{C} A, A ->{C} A)) => A^'s25 ->'s26 A^'s27
86+
|Found: (x$1: (A^ ->'s17 A^'s18, A^ ->'s19 A^'s20)^'s21) ->'s22 A^'s23 ->'s24 A^'s25
87+
|Required: ((A ->{C} A, A ->{C} A)) => A^'s26 ->'s27 A^'s28
8888
|
8989
|Note that capability C cannot be included in capture set {} of value x.
9090
|

tests/neg-custom-args/captures/real-try.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
| it leaks into outer capture set 's5 of value b.
4646
| The leakage occurred when trying to match the following types:
4747
|
48-
| Found: Cell[() ->{canThrow$4} Unit]
49-
| Required: Cell[() ->'s5 Unit]^'s6
48+
| Found: Cell[() ->{canThrow$4} Unit]^'s6
49+
| Required: Cell[() ->'s5 Unit]^'s7
5050
|
5151
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/unscoped-classifier.check

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,3 @@
1717
| method gg should be declared an update method to allow this.
1818
|
1919
| where: => refers to a fresh root capability in the type of parameter g
20-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/unscoped-classifier.scala:19:11 --------------------------
21-
19 | val b = B() // error but msg could be better
22-
| ^^^
23-
|Found: B^
24-
|Required: B^'s1
25-
|
26-
|Note that capability cap is not classified as trait Unscoped, therefore it
27-
|cannot be included in capture set 's1 of value b of Unscoped elements.
28-
|
29-
|where: ^ and cap refer to a fresh root capability classified as Nothing created in value b when constructing instance B
30-
|
31-
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/unscoped-classifier.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def test(g: () => Unit) =
1616
class E extends caps.Unscoped:
1717
def gg() = g() // error but msg could be better
1818

19-
val b = B() // error but msg could be better
19+
val b = B()
2020
val d = D() // ok (?)
2121
val _: D^{cap.only[Unscoped]} = d

tests/neg-custom-args/captures/unsound-reach-4.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/unsound-reach-4.scala:20:29 ------------------------------
99
20 | val backdoor: Foo[File^] = new Bar // error (follow-on, since the parent Foo[File^] of bar is illegal).
1010
| ^^^^^^^
11-
| Found: Bar
11+
| Found: Bar^'s1
1212
| Required: Foo[File^]
1313
|
1414
| Note that capability cap is not included in capture set {cap²}

tests/neg-custom-args/captures/unsound-reach.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/unsound-reach.scala:18:31 --------------------------------
99
18 | val backdoor: Foo[File^] = new Bar // error
1010
| ^^^^^^^
11-
| Found: Bar
11+
| Found: Bar^'s1
1212
| Required: Foo[File^]
1313
|
1414
| Note that capability cap is not included in capture set {cap²}
@@ -21,7 +21,7 @@
2121
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/unsound-reach.scala:27:32 --------------------------------
2222
27 | val backdoor: Foo2[File^] = new Bar2 // error
2323
| ^^^^^^^^
24-
| Found: Bar2
24+
| Found: Bar2^'s2
2525
| Required: Foo2[File^]
2626
|
2727
| Note that capability cap is not included in capture set {cap²}

0 commit comments

Comments
 (0)