aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnno Runne <enno@runne.net>2017-03-07 20:05:28 +0100
committerEnno Runne <enno@runne.net>2017-03-07 20:05:28 +0100
commit98465f930fe5d3f10401c454d6655da71243b923 (patch)
tree42888e27a553888a21628090e6aab562a96d8c83
parentc3ec6dfbdeadb2fc9e7ac191b4c1a4d6838e8a5b (diff)
downloaddotty-98465f930fe5d3f10401c454d6655da71243b923.tar.gz
dotty-98465f930fe5d3f10401c454d6655da71243b923.tar.bz2
dotty-98465f930fe5d3f10401c454d6655da71243b923.zip
Analysis of overloaded or recursive is harder than expected
Fall-back to reporting "overloaded or recursive needs type".
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java3
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala29
-rw-r--r--compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala5
-rw-r--r--compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala6
4 files changed, 17 insertions, 26 deletions
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java
index f6d0de352..a03e21d98 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java
@@ -52,8 +52,7 @@ public enum ErrorMessageID {
MixedLeftAndRightAssociativeOpsID,
CantInstantiateAbstractClassOrTraitID,
AnnotatedPrimaryConstructorRequiresModifierOrThisID,
- OverloadedMethodNeedsResultTypeID,
- RecursiveMethodNeedsResultTypeID,
+ OverloadedOrRecursiveMethodNeedsResultTypeID,
RecursiveValueNeedsResultTypeID,
CyclicReferenceInvolvingID,
CyclicReferenceInvolvingImplicitID,
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index 44ae98d82..a4db1b785 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -1162,23 +1162,18 @@ object messages {
|""".stripMargin
}
- case class OverloadedMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context)
- extends Message(OverloadedMethodNeedsResultTypeID) {
+ case class OverloadedOrRecursiveMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context)
+ extends Message(OverloadedOrRecursiveMethodNeedsResultTypeID) {
val kind = "Syntax"
- val msg = hl"""overloaded method ${tree} needs result type"""
+ val msg = hl"""overloaded or recursive method ${tree} needs return type"""
val explanation =
- hl"""|${tree} is overloaded and at least one definition of it calls another.
- |You need to specify the calling method's return type.
- """.stripMargin
- }
-
- case class RecursiveMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context)
- extends Message(RecursiveMethodNeedsResultTypeID) {
- val kind = "Syntax"
- val msg = hl"""recursive method ${tree} needs result type"""
- val explanation =
- hl"""|The definition of `${tree.name}` is recursive and you need to specify its type.
- """.stripMargin
+ hl"""Case 1: ${tree} is overloaded
+ |If there are multiple methods named `${tree.name}` and at least one definition of
+ |it calls another, you need to specify the calling method's return type.
+ |
+ |Case 2: ${tree} is recursive
+ |If `${tree.name}` calls itself on any path, you need to specify its return type.
+ |""".stripMargin
}
case class RecursiveValueNeedsResultType(tree: Names.TermName)(implicit ctx: Context)
@@ -1186,8 +1181,8 @@ object messages {
val kind = "Syntax"
val msg = hl"""recursive value ${tree.name} needs type"""
val explanation =
- hl"""|The definition of `${tree.name}` is recursive and you need to specify its type.
- """.stripMargin
+ hl"""The definition of `${tree.name}` is recursive and you need to specify its type.
+ |""".stripMargin
}
case class CyclicReferenceInvolving(denot: SymDenotation)(implicit ctx: Context)
diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
index 3a377bdc0..a1690955f 100644
--- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
+++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
@@ -32,10 +32,7 @@ object ErrorReporting {
if (cx.mode is Mode.InferringReturnType) {
cx.tree match {
case tree: untpd.DefDef if !tree.tpt.typeOpt.exists =>
- // TODO: analysis if tree is an overloaded method (or directly recursive)
- val overloaded = true
- if (overloaded) OverloadedMethodNeedsResultType(tree.name)
- else RecursiveMethodNeedsResultType(tree.name)
+ OverloadedOrRecursiveMethodNeedsResultType(tree.name)
case tree: untpd.ValDef if !tree.tpt.typeOpt.exists =>
RecursiveValueNeedsResultType(tree.name)
case _ =>
diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
index 0c40ec477..f11c6dd96 100644
--- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
+++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
@@ -227,11 +227,11 @@ class ErrorMessagesTests extends ErrorMessagesTest {
val defn = ictx.definitions
assertMessageCount(1, messages)
- val OverloadedMethodNeedsResultType(tree) :: Nil = messages
+ val OverloadedOrRecursiveMethodNeedsResultType(tree) :: Nil = messages
assertEquals("foo", tree.show)
}
- @Test @Ignore def recursiveMethodNeedsReturnType =
+ @Test def recursiveMethodNeedsReturnType =
checkMessagesAfter("frontend") {
"""
|class Scope() {
@@ -244,7 +244,7 @@ class ErrorMessagesTests extends ErrorMessagesTest {
val defn = ictx.definitions
assertMessageCount(1, messages)
- val RecursiveMethodNeedsResultType(tree) :: Nil = messages
+ val OverloadedOrRecursiveMethodNeedsResultType(tree) :: Nil = messages
assertEquals("i", tree.show)
}