diff options
author | Martin Odersky <odersky@gmail.com> | 2016-12-12 12:40:51 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-12-12 12:53:40 +0100 |
commit | e31a4856f1c35b889b775608836f7d6a6a4262d6 (patch) | |
tree | f8600415b3c67440598e261b44ca3fb51a9c3665 /compiler | |
parent | 4c1bf42414b7f7ed99653fe841b032eb11864f2a (diff) | |
download | dotty-e31a4856f1c35b889b775608836f7d6a6a4262d6.tar.gz dotty-e31a4856f1c35b889b775608836f7d6a6a4262d6.tar.bz2 dotty-e31a4856f1c35b889b775608836f7d6a6a4262d6.zip |
Better diagnosis for cyclic references caused by implicit search
Since we now allow to drop the explicit type of a local implicit val
it can happen that this causes a cyclic reference, namely when the
typechecking of the right-hand side involves an implicit search.
It's unpractical and fragile to avoid this. Instead we give now
a nice error message explaining the problem and how to fix it in
source code.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala | 8 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Namer.scala | 1 |
2 files changed, 7 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index a18c83ff8..a066fc04a 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -46,7 +46,13 @@ object ErrorReporting { errorMsg(msg, cx.outer) } } else msg - errorMsg(ex.show, ctx) + + 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.""" + else + errorMsg(ex.show, ctx) } def wrongNumberOfArgs(fntpe: Type, kind: String, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree], pos: Position)(implicit ctx: Context) = diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 4ca9f9e10..4bcdd5071 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1001,7 +1001,6 @@ class Namer { typer: Typer => def missingType(modifier: String) = { ctx.error(s"${modifier}type of implicit definition needs to be given explicitly", mdef.pos) sym.resetFlag(Implicit) - } if (sym is Implicit) mdef match { |