diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala | 15 | ||||
-rw-r--r-- | tests/neg/i2001.scala | 6 |
2 files changed, 10 insertions, 11 deletions
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) } diff --git a/tests/neg/i2001.scala b/tests/neg/i2001.scala new file mode 100644 index 000000000..82518890c --- /dev/null +++ b/tests/neg/i2001.scala @@ -0,0 +1,6 @@ +class A { + def odd(x: Int) = if (x == 0) false else !even(x-1) + def even(x: Int) = if (x == 0) true else !odd(x-1) // error: overloaded or recursive method needs result type + + lazy val x = x // error: recursive value needs type +} |