Skip to content

Commit 0696541

Browse files
committed
Mention classification when explaining FreshCaps in error messages
1 parent 36169a4 commit 0696541

15 files changed

+74
-68
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ object Capabilities:
162162
origin.explanation
163163
case _ =>
164164
i" created in ${hiddenSet.owner.sanitizedDescription}${origin.explanation}"
165-
i"a fresh root capability$originStr"
165+
val classifierStr =
166+
if hiddenSet.classifier != defn.AnyClass
167+
then i" classified as ${hiddenSet.classifier.name}"
168+
else ""
169+
i"a fresh root capability$classifierStr$originStr"
166170

167171
object FreshCap:
168172
def apply(origin: Origin)(using Context): FreshCap | GlobalCap.type =

project/Build.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,7 @@ object Build {
12721272
file(s"${baseDirectory.value}/src/scala/quoted/runtime/SplicedType.scala"),
12731273
file(s"${baseDirectory.value}/src/scala/quoted/runtime/StopMacroExpansion.scala"),
12741274
file(s"${baseDirectory.value}/src/scala/compiletime/Erased.scala"),
1275+
file(s"${baseDirectory.value}/src/scala/annotation/internal/onlyCapability.scala"),
12751276
)
12761277
)
12771278
lazy val `scala3-library-bootstrapped`: Project = project.in(file("library")).asDottyLibrary(Bootstrapped)
@@ -1408,6 +1409,7 @@ object Build {
14081409
file(s"${baseDirectory.value}/src/scala/quoted/runtime/SplicedType.scala"),
14091410
file(s"${baseDirectory.value}/src/scala/quoted/runtime/StopMacroExpansion.scala"),
14101411
file(s"${baseDirectory.value}/src/scala/compiletime/Erased.scala"),
1412+
file(s"${baseDirectory.value}/src/scala/annotation/internal/onlyCapability.scala"),
14111413
)
14121414
)
14131415

tests/neg-custom-args/captures/lazylists-exceptions.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| that type captures the root capability `cap`.
66
| This is often caused by a locally generated exception capability leaking as part of its result.
77
|
8-
| where: cap is a fresh root capability in the type of given instance canThrow$1
8+
| where: cap is a fresh root capability classified as Control in the type of given instance canThrow$1
99
37 | tabulate(10) { i =>
1010
38 | if i > 9 then throw Ex1()
1111
39 | i * i

tests/neg-custom-args/captures/linear-buffer-2.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
| of value buf1 with type Buffer[Int]^.
66
| This type hides capabilities {buf}
77
|
8-
| where: ^ refers to a fresh root capability in the type of value buf1
8+
| where: ^ refers to a fresh root capability classified as Mutable in the type of value buf1
99
-- Error: tests/neg-custom-args/captures/linear-buffer-2.scala:20:13 ---------------------------------------------------
1010
20 | val buf3 = buf1.append(4) // error
1111
| ^^^^
1212
| Separation failure: Illegal access to (buf1 : Buffer[Int]^), which was passed to a
1313
| @consume parameter or was used as a prefix to a @consume method on line 18
1414
| and therefore is no longer available.
1515
|
16-
| where: ^ refers to a fresh root capability in the type of value buf1
16+
| where: ^ refers to a fresh root capability classified as Mutable in the type of value buf1
1717
-- Error: tests/neg-custom-args/captures/linear-buffer-2.scala:28:13 ---------------------------------------------------
1818
28 | val buf3 = buf1.append(4) // error
1919
| ^^^^
2020
| Separation failure: Illegal access to (buf1 : Buffer[Int]^), which was passed to a
2121
| @consume parameter or was used as a prefix to a @consume method on line 25
2222
| and therefore is no longer available.
2323
|
24-
| where: ^ refers to a fresh root capability in the type of value buf1
24+
| where: ^ refers to a fresh root capability classified as Mutable in the type of value buf1
2525
-- Error: tests/neg-custom-args/captures/linear-buffer-2.scala:38:13 ---------------------------------------------------
2626
38 | val buf3 = buf1.append(4) // error
2727
| ^^^^
2828
| Separation failure: Illegal access to (buf1 : Buffer[Int]^), which was passed to a
2929
| @consume parameter or was used as a prefix to a @consume method on line 33
3030
| and therefore is no longer available.
3131
|
32-
| where: ^ refers to a fresh root capability in the type of value buf1
32+
| where: ^ refers to a fresh root capability classified as Mutable in the type of value buf1
3333
-- Error: tests/neg-custom-args/captures/linear-buffer-2.scala:42:4 ----------------------------------------------------
3434
42 | buf.append(1) // error
3535
| ^^^
3636
| Separation failure: (buf : Buffer[Int]^) appears in a loop, therefore it cannot
3737
| be passed to a @consume parameter or be used as a prefix of a @consume method call.
3838
|
39-
| where: ^ refers to a fresh root capability in the type of parameter buf
39+
| where: ^ refers to a fresh root capability classified as Mutable in the type of parameter buf

tests/neg-custom-args/captures/linear-buffer.check

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@
1111
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:19:17 -----------------------------------------------------
1212
19 | val buf3 = app(buf, 3) // error
1313
| ^^^
14-
| Separation failure: Illegal access to (buf : Buffer[Int]^), which was passed to a
15-
| @consume parameter or was used as a prefix to a @consume method on line 17
16-
| and therefore is no longer available.
14+
| Separation failure: Illegal access to (buf : Buffer[Int]^), which was passed to a
15+
| @consume parameter or was used as a prefix to a @consume method on line 17
16+
| and therefore is no longer available.
1717
|
18-
| where: ^ refers to a fresh root capability in the type of parameter buf
18+
| where: ^ refers to a fresh root capability classified as Mutable in the type of parameter buf
1919
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:26:17 -----------------------------------------------------
2020
26 | val buf3 = app(buf1, 4) // error
2121
| ^^^^
2222
| Separation failure: Illegal access to (buf1 : Buffer[Int]^), which was passed to a
2323
| @consume parameter or was used as a prefix to a @consume method on line 24
2424
| and therefore is no longer available.
2525
|
26-
| where: ^ refers to a fresh root capability in the type of value buf1
26+
| where: ^ refers to a fresh root capability classified as Mutable in the type of value buf1
2727
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:34:17 -----------------------------------------------------
2828
34 | val buf3 = app(buf1, 4) // error
2929
| ^^^^
3030
| Separation failure: Illegal access to (buf1 : Buffer[Int]^), which was passed to a
3131
| @consume parameter or was used as a prefix to a @consume method on line 31
3232
| and therefore is no longer available.
3333
|
34-
| where: ^ refers to a fresh root capability in the type of value buf1
34+
| where: ^ refers to a fresh root capability classified as Mutable in the type of value buf1
3535
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:44:17 -----------------------------------------------------
3636
44 | val buf3 = app(buf1, 4) // error
3737
| ^^^^
3838
| Separation failure: Illegal access to (buf1 : Buffer[Int]^), which was passed to a
3939
| @consume parameter or was used as a prefix to a @consume method on line 39
4040
| and therefore is no longer available.
4141
|
42-
| where: ^ refers to a fresh root capability in the type of value buf1
42+
| where: ^ refers to a fresh root capability classified as Mutable in the type of value buf1
4343
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:48:8 ------------------------------------------------------
4444
48 | app(buf, 1) // error
4545
| ^^^
4646
| Separation failure: (buf : Buffer[Int]^) appears in a loop, therefore it cannot
4747
| be passed to a @consume parameter or be used as a prefix of a @consume method call.
4848
|
49-
| where: ^ refers to a fresh root capability in the type of parameter buf
49+
| where: ^ refers to a fresh root capability classified as Mutable in the type of parameter buf

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
| Footprint set of third argument : {m2}
1414
| The two sets overlap at : {m2}
1515
|
16-
|where: cap is a fresh root capability created in method Test when checking argument to parameter y of method mul
16+
|where: cap is a fresh root capability classified as Mutable created in method Test when checking argument to parameter y of method mul
1717
-- Error: tests/neg-custom-args/captures/matrix.scala:30:11 ------------------------------------------------------------
1818
30 | mul1(m1, m2, m2) // error: will fail separation checking
1919
| ^^
@@ -29,4 +29,4 @@
2929
| Footprint set of third argument : {m2}
3030
| The two sets overlap at : {m2}
3131
|
32-
|where: cap is a fresh root capability created in method Test when checking argument to parameter y of method mul1
32+
|where: cap is a fresh root capability classified as Mutable created in method Test when checking argument to parameter y of method mul1

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,43 @@
1111
| that type captures the root capability `cap`.
1212
| This is often caused by a locally generated exception capability leaking as part of its result.
1313
|
14-
| where: cap is a fresh root capability in the type of given instance canThrow$1
14+
| where: cap is a fresh root capability classified as Control in the type of given instance canThrow$1
1515
15 | () => foo(1)
1616
16 | catch
1717
17 | case _: Ex1 => ???
1818
18 | case _: Ex2 => ???
1919
-- Error: tests/neg-custom-args/captures/real-try.scala:20:10 ----------------------------------------------------------
2020
20 | val x = try // error
2121
| ^
22-
| The result of `try` cannot have type () ->{cap.rd} Unit since
23-
| that type captures the root capability `cap`.
24-
| This is often caused by a locally generated exception capability leaking as part of its result.
22+
| The result of `try` cannot have type () ->{cap.rd} Unit since
23+
| that type captures the root capability `cap`.
24+
| This is often caused by a locally generated exception capability leaking as part of its result.
2525
|
26-
| where: cap is a fresh root capability in the type of given instance canThrow$2
26+
| where: cap is a fresh root capability classified as Control in the type of given instance canThrow$2
2727
21 | () => foo(1)
2828
22 | catch
2929
23 | case _: Ex1 => ???
3030
24 | case _: Ex2 => ???
3131
-- Error: tests/neg-custom-args/captures/real-try.scala:26:10 ----------------------------------------------------------
3232
26 | val y = try // error
3333
| ^
34-
| The result of `try` cannot have type () ->{cap.rd} Cell[Unit]^? since
35-
| that type captures the root capability `cap`.
36-
| This is often caused by a locally generated exception capability leaking as part of its result.
34+
| The result of `try` cannot have type () ->{cap.rd} Cell[Unit]^? since
35+
| that type captures the root capability `cap`.
36+
| This is often caused by a locally generated exception capability leaking as part of its result.
3737
|
38-
| where: cap is a fresh root capability in the type of given instance canThrow$3
38+
| where: cap is a fresh root capability classified as Control in the type of given instance canThrow$3
3939
27 | () => Cell(foo(1))
4040
28 | catch
4141
29 | case _: Ex1 => ???
4242
30 | case _: Ex2 => ???
4343
-- Error: tests/neg-custom-args/captures/real-try.scala:32:10 ----------------------------------------------------------
4444
32 | val b = try // error
4545
| ^
46-
| The result of `try` cannot have type Cell[() ->{cap.rd} Unit]^? since
47-
| the part () ->{cap.rd} Unit of that type captures the root capability `cap`.
48-
| This is often caused by a locally generated exception capability leaking as part of its result.
46+
| The result of `try` cannot have type Cell[() ->{cap.rd} Unit]^? since
47+
| the part () ->{cap.rd} Unit of that type captures the root capability `cap`.
48+
| This is often caused by a locally generated exception capability leaking as part of its result.
4949
|
50-
| where: cap is a fresh root capability in the type of given instance canThrow$4
50+
| where: cap is a fresh root capability classified as Control in the type of given instance canThrow$4
5151
33 | Cell(() => foo(1))
5252
34 | catch
5353
35 | case _: Ex1 => ???

tests/neg-custom-args/captures/ro-mut-conformance.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| Found: (a : Ref)
1010
| Required: Ref^
1111
|
12-
| where: ^ refers to a fresh root capability in the type of value t
12+
| where: ^ refers to a fresh root capability classified as Mutable in the type of value t
1313
|
1414
| Note that {cap} is an exclusive capture set of the mutable type Ref^,
1515
| it cannot subsume a read-only capture set of the mutable type (a : Ref).
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrude-mut.scala:9:8 ------------------------------
22
9 | a = a1 // error
33
| ^^
4-
| Found: (a1 : A^)
5-
| Required: A^²
4+
|Found: (a1 : A^)
5+
|Required: A^²
66
|
7-
| where: ^ refers to a fresh root capability created in value a1 when constructing mutable A
8-
| ^² refers to a fresh root capability in the type of variable a
7+
|where: ^ refers to a fresh root capability classified as Mutable created in value a1 when constructing mutable A
8+
| ^² refers to a fresh root capability classified as Mutable in the type of variable a
99
|
1010
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/sep-box.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
| Footprint set of second argument : {h2.value*, xs*}
1414
| The two sets overlap at : {xs*}
1515
|
16-
|where: ^ refers to a fresh root capability created in method test when checking argument to parameter x of method par
16+
|where: ^ refers to a fresh root capability classified as Mutable created in method test when checking argument to parameter x of method par

0 commit comments

Comments
 (0)