Skip to content

Commit ea0eca3

Browse files
committed
Move UseAfterConsume to messages.scala
1 parent f78e47d commit ea0eca3

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -443,39 +443,13 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
443443
|No clashing definitions were found. This might point to an internal error.""",
444444
tree.srcPos)
445445

446-
class UseAfterConsume(ref: Capability, consumedLoc: SrcPos, useLoc: SrcPos)(using Context) extends reporting.Message(reporting.ErrorMessageID.NoExplanationID):
447-
def kind = reporting.MessageKind.NoKind
448-
449-
protected def msg(using Context): String = ""
450-
451-
protected def explain(using Context): String = ""
452-
453-
override def leading(using Context): Option[String] = Some(
454-
em"""Separation failure: Illegal access to $ref, which was passed to a
455-
|consume parameter or was used as a prefix to a consume method
456-
|and therefore is no longer available.""".message
457-
)
458-
459-
override def parts(using Context): List[reporting.Message.MessagePart] = List(
460-
reporting.Message.MessagePart(
461-
"The capability was consumed here.",
462-
consumedLoc.sourcePos,
463-
isPrimary = false
464-
),
465-
reporting.Message.MessagePart(
466-
"Then, it was used here",
467-
useLoc.sourcePos,
468-
isPrimary = true
469-
)
470-
)
471-
472446
/** Report a failure where a previously consumed capability is used again,
473447
* @param ref the capability that is used after being consumed
474448
* @param loc the position where the capability was consumed
475449
* @param pos the position where the capability was used again
476450
*/
477451
def consumeError(ref: Capability, loc: SrcPos, pos: SrcPos)(using Context): Unit =
478-
report.error(UseAfterConsume(ref, loc, pos), pos)
452+
report.error(reporting.UseAfterConsume(ref, loc.sourcePos, pos.sourcePos), pos)
479453

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

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,3 +3760,27 @@ final class EncodedPackageName(name: Name)(using Context) extends SyntaxMsg(Enco
37603760
|or `myfile-test.scala` can produce encoded names for the generated package objects.
37613761
|
37623762
|In this case, the name `$name` is encoded as `${name.encode}`."""
3763+
3764+
class UseAfterConsume(ref: cc.Capabilities.Capability, consumedLoc: SourcePosition, useLoc: SourcePosition)(using Context)
3765+
extends TypeMsg(NoExplanationID):
3766+
protected def msg(using Context): String =
3767+
i"""Separation failure: Illegal access to $ref, which was passed to a
3768+
|consume parameter or was used as a prefix to a consume method
3769+
|and therefore is no longer available."""
3770+
3771+
protected def explain(using Context): String = ""
3772+
3773+
override def leading(using Context): Option[String] = Some(message)
3774+
3775+
override def parts(using Context): List[Message.MessagePart] = List(
3776+
Message.MessagePart(
3777+
"The capability was consumed here.",
3778+
consumedLoc,
3779+
isPrimary = false
3780+
),
3781+
Message.MessagePart(
3782+
"Then, it was used here",
3783+
useLoc,
3784+
isPrimary = true
3785+
)
3786+
)

0 commit comments

Comments
 (0)