diff options
author | odersky <odersky@gmail.com> | 2017-02-24 08:27:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-24 08:27:04 +0100 |
commit | db24246e90f4b8afcaf1fc66df99d38d9a2cb736 (patch) | |
tree | 7f02f409e8e5233be94b3908531610ab7ffcf695 /compiler | |
parent | 2699715684e9ea474001e9fc85bb3c7d25ed1ca5 (diff) | |
parent | 4b494abf8bf113b738b013bf27448b4b8b61a7cc (diff) | |
download | dotty-db24246e90f4b8afcaf1fc66df99d38d9a2cb736.tar.gz dotty-db24246e90f4b8afcaf1fc66df99d38d9a2cb736.tar.bz2 dotty-db24246e90f4b8afcaf1fc66df99d38d9a2cb736.zip |
Merge pull request #2026 from dotty-staging/fix-#2001
Better error messages for missing type of recursive definitions
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index 9d6a01ab7..0978c2c1e 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -31,28 +31,21 @@ object ErrorReporting { def errorMsg(msg: String, cx: Context): String = if (cx.mode is Mode.InferringReturnType) { cx.tree match { - case tree: untpd.ValOrDefDef => - // Dotty deviation: Was Trees.ValOrDefDef[_], but this gives ValOrDefDef[Nothing] instead of - // ValOrDefDel[Null]. Scala handles it, but it looks accidental because bounds propagation - // fails if the parameter is invariant or cotravariant. - // See test pending/pos/boundspropagation.scala - val treeSym = ctx.symOfContextTree(tree) - if (treeSym.exists && treeSym.name == cycleSym.name && treeSym.owner == cycleSym.owner) { - val result = if (cycleSym is Method) " result" else "" - em"overloaded or recursive $cycleSym needs$result type" - } - else errorMsg(msg, cx.outer) + case tree: untpd.DefDef if !tree.tpt.typeOpt.exists => + em"overloaded or recursive method ${tree.name} needs result type" + case tree: untpd.ValDef if !tree.tpt.typeOpt.exists => + em"recursive value ${tree.name} needs type" case _ => errorMsg(msg, cx.outer) } } else msg - if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm) - em"""cyclic reference involving implicit $cycleSym + 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) + else + errorMsg(ex.show, ctx) } def wrongNumberOfTypeArgs(fntpe: Type, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree], pos: Position)(implicit ctx: Context) = |