Skip to content

Commit 7089e83

Browse files
committed
Use precise consume reason
1 parent f02de95 commit 7089e83

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
461461
*/
462462
def consumeError(ref: Capability, loc: (SrcPos, TypeRole), pos: SrcPos)(using Context): Unit =
463463
val (locPos, role) = loc
464-
report.error(
465-
em"""Separation failure: Illegal access to $ref, which was ${role.howConsumed}
466-
|on line ${locPos.line + 1} and therefore is no longer available.""",
467-
pos)
464+
report.error(reporting.UseAfterConsume(ref, locPos.sourcePos, pos.sourcePos, role.howConsumed), pos)
468465

469466
/** Report a failure where a capability is consumed in a loop.
470467
* @param ref the capability

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,11 +3742,10 @@ final class EncodedPackageName(name: Name)(using Context) extends SyntaxMsg(Enco
37423742
|
37433743
|In this case, the name `$name` is encoded as `${name.encode}`."""
37443744

3745-
class UseAfterConsume(ref: cc.Capabilities.Capability, consumedLoc: SourcePosition, useLoc: SourcePosition)(using Context)
3745+
class UseAfterConsume(ref: cc.Capabilities.Capability, consumedLoc: SourcePosition, useLoc: SourcePosition, howConsumed: => String)(using Context)
37463746
extends TypeMsg(NoExplanationID):
37473747
protected def msg(using Context): String =
3748-
i"""Separation failure: Illegal access to $ref, which was passed to a
3749-
|consume parameter or was used as a prefix to a consume method
3748+
i"""Separation failure: Illegal access to $ref, which was $howConsumed
37503749
|and therefore is no longer available."""
37513750

37523751
protected def explain(using Context): String = ""

tests/neg-custom-args/captures/consume-twice-same-line.check

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-- Type Error: tests/neg-custom-args/captures/consume-twice-same-line.scala:5:16 ---------------------------------------
2-
Separation failure: Illegal access to (x : Object^), which was passed to a
3-
consume parameter or was used as a prefix to a consume method
2+
Separation failure: Illegal access to (x : Object^), which was passed as a consume parameter to method send
43
and therefore is no longer available.
54

65
where: ^ refers to a fresh root capability in the type of parameter x
@@ -10,8 +9,7 @@ where: ^ refers to a fresh root capability in the type of parameter x
109
| The capability was consumed here.
1110

1211
-- Type Error: tests/neg-custom-args/captures/consume-twice-same-line.scala:8:16 ---------------------------------------
13-
Separation failure: Illegal access to (x : Object^), which was passed to a
14-
consume parameter or was used as a prefix to a consume method
12+
Separation failure: Illegal access to (x : Object^), which was passed as a consume parameter to method send
1513
and therefore is no longer available.
1614

1715
where: ^ refers to a fresh root capability in the type of parameter x
@@ -21,8 +19,7 @@ where: ^ refers to a fresh root capability in the type of parameter x
2119
| The capability was consumed here.
2220

2321
-- Type Error: tests/neg-custom-args/captures/consume-twice-same-line.scala:8:25 ---------------------------------------
24-
Separation failure: Illegal access to (x : Object^), which was passed to a
25-
consume parameter or was used as a prefix to a consume method
22+
Separation failure: Illegal access to (x : Object^), which was passed as a consume parameter to method send
2623
and therefore is no longer available.
2724

2825
where: ^ refers to a fresh root capability in the type of parameter x

tests/neg-custom-args/captures/consume-twice.check

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-- Type Error: tests/neg-custom-args/captures/consume-twice.scala:6:7 --------------------------------------------------
2-
Separation failure: Illegal access to (x : Object^), which was passed to a
3-
consume parameter or was used as a prefix to a consume method
2+
Separation failure: Illegal access to (x : Object^), which was passed as a consume parameter to method send
43
and therefore is no longer available.
54

65
where: ^ refers to a fresh root capability in the type of parameter x

0 commit comments

Comments
 (0)