File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -31,17 +31,10 @@ object ErrorReporting {
31
31
def errorMsg (msg : String , cx : Context ): String =
32
32
if (cx.mode is Mode .InferringReturnType ) {
33
33
cx.tree match {
34
- case tree : untpd.ValOrDefDef =>
35
- // Dotty deviation: Was Trees.ValOrDefDef[_], but this gives ValOrDefDef[Nothing] instead of
36
- // ValOrDefDel[Null]. Scala handles it, but it looks accidental because bounds propagation
37
- // fails if the parameter is invariant or cotravariant.
38
- // See test pending/pos/boundspropagation.scala
39
- val treeSym = ctx.symOfContextTree(tree)
40
- if (treeSym.exists && treeSym.name == cycleSym.name && treeSym.owner == cycleSym.owner) {
41
- val result = if (cycleSym is Method ) " result" else " "
42
- em " overloaded or recursive $cycleSym needs $result type "
43
- }
44
- else errorMsg(msg, cx.outer)
34
+ case tree : untpd.DefDef if ! tree.tpt.typeOpt.exists =>
35
+ em " overloaded or recursive method ${tree.name} needs result type "
36
+ case tree : untpd.ValDef if ! tree.tpt.typeOpt.exists =>
37
+ em " recursive value ${tree.name} needs type "
45
38
case _ =>
46
39
errorMsg(msg, cx.outer)
47
40
}
Original file line number Diff line number Diff line change
1
+ class A {
2
+ def odd (x : Int ) = if (x == 0 ) false else ! even(x- 1 )
3
+ def even (x : Int ) = if (x == 0 ) true else ! odd(x- 1 ) // error: overloaded or recursive method needs result type
4
+
5
+ lazy val x = x // error: recursive value needs type
6
+ }
You can’t perform that action at this time.
0 commit comments