diff options
Diffstat (limited to 'compiler/src')
-rw-r--r-- | compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 11 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala | 6 |
2 files changed, 13 insertions, 4 deletions
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 489165e56..ce3cb48ec 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -899,4 +899,15 @@ object messages { val msg = hl"trying to define package with same name as `$existing`" val explanation = "" } + + case class CyclicImplicitVal(cycleSym: Symbol)(implicit ctx: Context) + extends Message(34) { + val kind = "Cyclic Reference" + val msg = em"cyclic reference involving $cycleSym" + val explanation = + hl"""|This happens when the right hand-side of $cycleSym's definition + |involves an implicit search. + | + |To avoid the error, give $cycleSym an explicit type.""" + } } diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index a066fc04a..5709bfbf9 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -28,7 +28,7 @@ object ErrorReporting { def cyclicErrorMsg(ex: CyclicReference)(implicit ctx: Context) = { val cycleSym = ex.denot.symbol - def errorMsg(msg: String, cx: Context): String = + def errorMsg(msg: String, cx: Context): Message = if (cx.mode is Mode.InferringReturnType) { cx.tree match { case tree: untpd.ValOrDefDef => @@ -48,9 +48,7 @@ object ErrorReporting { } else msg if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm) - em"""cyclic reference involving implicit $cycleSym - |This happens when the right hand-side of $cycleSym's definition involves an implicit search. - |To avoid the error, give $cycleSym an explicit type.""" + CyclicImplicitVal(cycleSym) else errorMsg(ex.show, ctx) } |