Skip to content

Commit 559e493

Browse files
committed
Add CyclicImplicitVal error to messages
1 parent 2082307 commit 559e493

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,4 +899,15 @@ object messages {
899899
val msg = hl"trying to define package with same name as `$existing`"
900900
val explanation = ""
901901
}
902+
903+
case class CyclicImplicitVal(cycleSym: Symbol)(implicit ctx: Context)
904+
extends Message(34) {
905+
val kind = "Cyclic Reference"
906+
val msg = em"cyclic reference involving $cycleSym"
907+
val explanation =
908+
hl"""|This happens when the right hand-side of $cycleSym's definition
909+
|involves an implicit search.
910+
|
911+
|To avoid the error, give $cycleSym an explicit type."""
912+
}
902913
}

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object ErrorReporting {
2828

2929
def cyclicErrorMsg(ex: CyclicReference)(implicit ctx: Context) = {
3030
val cycleSym = ex.denot.symbol
31-
def errorMsg(msg: String, cx: Context): String =
31+
def errorMsg(msg: String, cx: Context): Message =
3232
if (cx.mode is Mode.InferringReturnType) {
3333
cx.tree match {
3434
case tree: untpd.ValOrDefDef =>
@@ -48,9 +48,7 @@ object ErrorReporting {
4848
} else msg
4949

5050
if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm)
51-
em"""cyclic reference involving implicit $cycleSym
52-
|This happens when the right hand-side of $cycleSym's definition involves an implicit search.
53-
|To avoid the error, give $cycleSym an explicit type."""
51+
CyclicImplicitVal(cycleSym)
5452
else
5553
errorMsg(ex.show, ctx)
5654
}

0 commit comments

Comments
 (0)