From c6a09827b2c871cf85bbd0b87c55acb8344d3b97 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 23 Feb 2017 13:10:28 +0100 Subject: Better error messages for missing type of recursive definitions --- compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'compiler/src') diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index 9d6a01ab7..20946b530 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -31,17 +31,10 @@ 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) } -- cgit v1.2.3