Skip to content

Commit 0f7f56f

Browse files
committed
Use sub-diagnostics for consume error
1 parent faf1a62 commit 0f7f56f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,14 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
454454
|No clashing definitions were found. This might point to an internal error.""",
455455
tree.srcPos)
456456

457+
class UseAfterConsume(ref: Capability, consumedLoc: SrcPos, useLoc: SrcPos)(using Context) extends reporting.Diagnostic.Error(
458+
em"""Separation failure: Illegal access to $ref, which was consumed
459+
|and therefore is no longer available.""",
460+
useLoc.sourcePos
461+
):
462+
addSubdiag(em"""$ref was passed to a consume parameter or
463+
|was used as a prefix of a consume method here.""", consumedLoc.sourcePos)
464+
457465
/** Report a failure where a previously consumed capability is used again,
458466
* @param ref the capability that is used after being consumed
459467
* @param loc the position where the capability was consumed
@@ -465,6 +473,8 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
465473
em"""Separation failure: Illegal access to $ref, which was ${role.howConsumed}
466474
|on line ${locPos.line + 1} and therefore is no longer available.""",
467475
pos)
476+
// def consumeError(ref: Capability, loc: SrcPos, pos: SrcPos)(using Context): Unit =
477+
// ctx.reporter.report(UseAfterConsume(ref, loc, pos))
468478

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

0 commit comments

Comments
 (0)