From ce333b1fe852c2a6cb62486f31d336f4ecaac275 Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Fri, 24 Feb 2017 19:55:07 +0100 Subject: Change 'overloaded/recursive method/value needs type' to Message (see #2026) --- .../dotc/reporting/diagnostic/ErrorMessageID.java | 3 +++ .../tools/dotc/reporting/diagnostic/messages.scala | 28 ++++++++++++++++++++++ .../dotty/tools/dotc/typer/ErrorReporting.scala | 10 ++++---- .../tools/dotc/reporting/ErrorMessagesTests.scala | 19 +++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) (limited to 'compiler') diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index 2bf15cb7c..75e1d4cb2 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -51,6 +51,9 @@ public enum ErrorMessageID { ExpectedTokenButFoundID, MixedLeftAndRightAssociativeOpsID, CantInstantiateAbstractClassOrTraitID, + OverloadedOrRecursiveMethodNeedsResultTypeID, + RecursiveValueNeedsResultTypeID, + CyclicReferenceInvolvingImplicitID, ; public int errorNumber() { diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 34190c114..8d34d97ed 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1146,4 +1146,32 @@ object messages { |""".stripMargin } + case class OverloadedOrRecursiveMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context) + extends Message(OverloadedOrRecursiveMethodNeedsResultTypeID) { + val kind = "Syntax" + val msg = hl"""overloaded or recursive method ${tree} needs result type""" + val explanation = + hl"""""".stripMargin + } + + case class RecursiveValueNeedsResultType(tree: Names.TermName)(implicit ctx: Context) + extends Message(RecursiveValueNeedsResultTypeID) { + val kind = "Syntax" + val msg = hl"""recursive value ${tree.name} needs type""" + val explanation = + hl"""""".stripMargin + } + + case class CyclicReferenceInvolvingImplicit(cycleSym: Symbol)(implicit ctx: Context) + extends Message(CyclicReferenceInvolvingImplicitID) { + val kind = "Syntax" + val msg = hl"""cyclic reference involving implicit $cycleSym""" + val explanation = + hl"""|This happens when the right hand-side of $cycleSym's definition involves an implicit search. + |To avoid the error, give $cycleSym an explicit type. + |""".stripMargin + } + + + } diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index 0978c2c1e..f23b85c58 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -28,22 +28,20 @@ object ErrorReporting { def cyclicErrorMsg(ex: CyclicReference)(implicit ctx: Context) = { val cycleSym = ex.denot.symbol - def errorMsg(msg: String, cx: Context): String = + def errorMsg(msg: String, cx: Context): Message = if (cx.mode is Mode.InferringReturnType) { cx.tree match { case tree: untpd.DefDef if !tree.tpt.typeOpt.exists => - em"overloaded or recursive method ${tree.name} needs result type" + OverloadedOrRecursiveMethodNeedsResultType(tree.name) case tree: untpd.ValDef if !tree.tpt.typeOpt.exists => - em"recursive value ${tree.name} needs type" + RecursiveValueNeedsResultType(tree.name) case _ => errorMsg(msg, cx.outer) } } else msg 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.""" + CyclicReferenceInvolvingImplicit(cycleSym) else errorMsg(ex.show, ctx) } diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index 971a40a1b..71d62405a 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -198,4 +198,23 @@ class ErrorMessagesTests extends ErrorMessagesTest { assertTrue("expected trait", isTrait) } + @Test def cantInstantiateTrait = + checkMessagesAfter("refchecks") { + """ + |object Scope { + | trait Concept + | new Concept() + |} + """.stripMargin + } + .expect { (ictx, messages) => + implicit val ctx: Context = ictx + val defn = ictx.definitions + + assertMessageCount(1, messages) + val CantInstantiateAbstractClassOrTrait(cls, isTrait) :: Nil = messages + assertEquals("Concept", cls.name.show) + assertTrue("expected trait", isTrait) + } + } -- cgit v1.2.3 From 34e3508cccbbcc49554a4c5b13419769cc3c7bf9 Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Sat, 4 Mar 2017 16:32:33 +0100 Subject: Explanations for recursive/cyclic type requirements --- .../tools/dotc/reporting/diagnostic/messages.scala | 44 ++++++++-------- .../tools/dotc/reporting/ErrorMessagesTests.scala | 58 ++++++++++++++++++++++ 2 files changed, 81 insertions(+), 21 deletions(-) (limited to 'compiler') diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index f2f69b6cc..9d899923b 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1146,46 +1146,48 @@ object messages { |""".stripMargin } + case class AnnotatedPrimaryConstructorRequiresModifierOrThis(cls: Name)(implicit ctx: Context) + extends Message(AnnotatedPrimaryConstructorRequiresModifierOrThisID) { + val kind = "Syntax" + val msg = hl"""${"private"}, ${"protected"}, or ${"this"} expected for annotated primary constructor""" + val explanation = + hl"""|When using annotations with a primary constructor of a class, + |the annotation must be followed by an access modifier + |(${"private"} or ${"protected"}) or ${"this"}. + | + |For example: + | ${"class Sample @deprecated this(param: Parameter) { ..."} + | ^^^^ + |""".stripMargin + } + case class OverloadedOrRecursiveMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context) extends Message(OverloadedOrRecursiveMethodNeedsResultTypeID) { val kind = "Syntax" val msg = hl"""overloaded or recursive method ${tree} needs result type""" val explanation = - hl""" - | - """.stripMargin + 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 RecursiveValueNeedsResultType(tree: Names.TermName)(implicit ctx: Context) - extends Message(RecursiveValueNeedsResultTypeID) { + extends Message(RecursiveValueNeedsResultTypeID) { val kind = "Syntax" val msg = hl"""recursive value ${tree.name} needs type""" val explanation = - hl"""""".stripMargin + hl"""|The definition of `${tree.name}` is recursive and you need to specify its type. + """.stripMargin } case class CyclicReferenceInvolvingImplicit(cycleSym: Symbol)(implicit ctx: Context) - extends Message(CyclicReferenceInvolvingImplicitID) { + extends Message(CyclicReferenceInvolvingImplicitID) { val kind = "Syntax" val msg = hl"""cyclic reference involving implicit $cycleSym""" val explanation = hl"""|This happens when the right hand-side of $cycleSym's definition involves an implicit search. - |To avoid the error, give $cycleSym an explicit type. + |To avoid this error, give `${cycleSym.name}` an explicit type. |""".stripMargin } - case class AnnotatedPrimaryConstructorRequiresModifierOrThis(cls: Name)(implicit ctx: Context) - extends Message(AnnotatedPrimaryConstructorRequiresModifierOrThisID) { - val kind = "Syntax" - val msg = hl"""${"private"}, ${"protected"}, or ${"this"} expected for annotated primary constructor""" - val explanation = - hl"""|When using annotations with a primary constructor of a class, - |the annotation must be followed by an access modifier - |(${"private"} or ${"protected"}) or ${"this"}. - | - |For example: - | ${"class Sample @deprecated this(param: Parameter) { ..."} - | ^^^^ - |""".stripMargin - } } diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index d6e687a1e..257d40bb0 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -212,4 +212,62 @@ class ErrorMessagesTests extends ErrorMessagesTest { val AnnotatedPrimaryConstructorRequiresModifierOrThis(cls) :: Nil = messages assertEquals("AnotherClass", cls.show) } + + @Test def overloadedMethodNeedsReturnType = + checkMessagesAfter("frontend") { + """ + |class Scope() { + | def foo(i: Int) = foo(i.toString) + | def foo(s: String) = s + |} + """.stripMargin + } + .expect { (ictx, messages) => + implicit val ctx: Context = ictx + val defn = ictx.definitions + + assertMessageCount(1, messages) + val OverloadedOrRecursiveMethodNeedsResultType(tree) :: Nil = messages + assertEquals("foo", tree.show) + } + + @Test def recursiveValueNeedsReturnType = + checkMessagesAfter("frontend") { + """ + |class Scope() { + | lazy val i = i + 5 + |} + """.stripMargin + } + .expect { (ictx, messages) => + implicit val ctx: Context = ictx + val defn = ictx.definitions + + assertMessageCount(1, messages) + val RecursiveValueNeedsResultType(tree) :: Nil = messages + assertEquals("i", tree.show) + } + + @Test def cyclicReferenceInvolvingImplicit = + checkMessagesAfter("frontend") { + """ + |object implicitDefs { + | def foo(implicit x: String) = 1 + | def bar() = { + | implicit val x = foo + | x + | } + |} + """.stripMargin + } + .expect { (ictx, messages) => + implicit val ctx: Context = ictx + val defn = ictx.definitions + + assertMessageCount(1, messages) + val CyclicReferenceInvolvingImplicit(tree) :: Nil = messages + assertEquals("x", tree.name.show) + } + + } -- cgit v1.2.3 From c3ec6dfbdeadb2fc9e7ac191b4c1a4d6838e8a5b Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Sun, 5 Mar 2017 22:26:59 +0100 Subject: More detail in error messages Split error messages for recursive method and overloaded method needs type into two (but did not solve the analysis which to show). Make CyclicReference type error construct corresponding error message. --- compiler/src/dotty/tools/dotc/core/Types.scala | 3 +- .../dotc/reporting/diagnostic/ErrorMessageID.java | 4 ++- .../tools/dotc/reporting/diagnostic/messages.scala | 26 +++++++++++++-- .../dotty/tools/dotc/typer/ErrorReporting.scala | 9 +++-- .../tools/dotc/reporting/ErrorMessagesTests.scala | 39 ++++++++++++++++++++-- 5 files changed, 71 insertions(+), 10 deletions(-) (limited to 'compiler') diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 200e94a1e..f49d65350 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -19,6 +19,7 @@ import util.Positions.{Position, NoPosition} import util.Stats._ import util.{DotClass, SimpleMap} import reporting.diagnostic.Message +import reporting.diagnostic.messages.CyclicReferenceInvolving import ast.tpd._ import ast.TreeTypeMap import printing.Texts._ @@ -3856,7 +3857,7 @@ object Types { class CyclicReference private (val denot: SymDenotation) extends TypeError(s"cyclic reference involving $denot") { - def show(implicit ctx: Context) = s"cyclic reference involving ${denot.show}" + def toMessage(implicit ctx: Context) = CyclicReferenceInvolving(denot) } object CyclicReference { diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index 02869e752..f6d0de352 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -52,8 +52,10 @@ public enum ErrorMessageID { MixedLeftAndRightAssociativeOpsID, CantInstantiateAbstractClassOrTraitID, AnnotatedPrimaryConstructorRequiresModifierOrThisID, - OverloadedOrRecursiveMethodNeedsResultTypeID, + OverloadedMethodNeedsResultTypeID, + RecursiveMethodNeedsResultTypeID, 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 9d899923b..44ae98d82 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -18,6 +18,7 @@ import dotc.parsing.Tokens import printing.Highlighting._ import printing.Formatting import ErrorMessageID._ +import dotty.tools.dotc.core.SymDenotations.SymDenotation object messages { @@ -1161,16 +1162,25 @@ object messages { |""".stripMargin } - case class OverloadedOrRecursiveMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context) - extends Message(OverloadedOrRecursiveMethodNeedsResultTypeID) { + case class OverloadedMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context) + extends Message(OverloadedMethodNeedsResultTypeID) { val kind = "Syntax" - val msg = hl"""overloaded or recursive method ${tree} needs result type""" + val msg = hl"""overloaded method ${tree} needs result 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 + } + case class RecursiveValueNeedsResultType(tree: Names.TermName)(implicit ctx: Context) extends Message(RecursiveValueNeedsResultTypeID) { val kind = "Syntax" @@ -1180,6 +1190,16 @@ object messages { """.stripMargin } + case class CyclicReferenceInvolving(denot: SymDenotation)(implicit ctx: Context) + extends Message(CyclicReferenceInvolvingID) { + val kind = "Syntax" + val msg = hl"""cyclic reference involving $denot""" + val explanation = + hl"""|$denot is declared as part of a cycle which makes it impossible for the + |compiler to decide upon ${denot.name}'s type. + |""".stripMargin + } + case class CyclicReferenceInvolvingImplicit(cycleSym: Symbol)(implicit ctx: Context) extends Message(CyclicReferenceInvolvingImplicitID) { val kind = "Syntax" diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index f23b85c58..3a377bdc0 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -28,11 +28,14 @@ object ErrorReporting { def cyclicErrorMsg(ex: CyclicReference)(implicit ctx: Context) = { val cycleSym = ex.denot.symbol - def errorMsg(msg: String, cx: Context): Message = + def errorMsg(msg: Message, cx: Context): Message = if (cx.mode is Mode.InferringReturnType) { cx.tree match { case tree: untpd.DefDef if !tree.tpt.typeOpt.exists => - OverloadedOrRecursiveMethodNeedsResultType(tree.name) + // TODO: analysis if tree is an overloaded method (or directly recursive) + val overloaded = true + if (overloaded) OverloadedMethodNeedsResultType(tree.name) + else RecursiveMethodNeedsResultType(tree.name) case tree: untpd.ValDef if !tree.tpt.typeOpt.exists => RecursiveValueNeedsResultType(tree.name) case _ => @@ -43,7 +46,7 @@ object ErrorReporting { if (cycleSym.is(Implicit, butNot = Method) && cycleSym.owner.isTerm) CyclicReferenceInvolvingImplicit(cycleSym) else - errorMsg(ex.show, ctx) + errorMsg(ex.toMessage, ctx) } def wrongNumberOfTypeArgs(fntpe: Type, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree], pos: Position)(implicit ctx: Context) = diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index 257d40bb0..0c40ec477 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -6,7 +6,7 @@ import core.Contexts.Context import diagnostic.messages._ import dotty.tools.dotc.parsing.Tokens import org.junit.Assert._ -import org.junit.Test +import org.junit.{Ignore, Test} class ErrorMessagesTests extends ErrorMessagesTest { // In the case where there are no errors, we can do "expectNoErrors" in the @@ -227,10 +227,27 @@ class ErrorMessagesTests extends ErrorMessagesTest { val defn = ictx.definitions assertMessageCount(1, messages) - val OverloadedOrRecursiveMethodNeedsResultType(tree) :: Nil = messages + val OverloadedMethodNeedsResultType(tree) :: Nil = messages assertEquals("foo", tree.show) } + @Test @Ignore def recursiveMethodNeedsReturnType = + checkMessagesAfter("frontend") { + """ + |class Scope() { + | def i = i + 5 + |} + """.stripMargin + } + .expect { (ictx, messages) => + implicit val ctx: Context = ictx + val defn = ictx.definitions + + assertMessageCount(1, messages) + val RecursiveMethodNeedsResultType(tree) :: Nil = messages + assertEquals("i", tree.show) + } + @Test def recursiveValueNeedsReturnType = checkMessagesAfter("frontend") { """ @@ -248,6 +265,24 @@ class ErrorMessagesTests extends ErrorMessagesTest { assertEquals("i", tree.show) } + @Test def cyclicReferenceInvolving = + checkMessagesAfter("frontend") { + """ + |class A { + | val x: T = ??? + | type T <: x.type // error: cyclic reference involving value x + |} + """.stripMargin + } + .expect { (ictx, messages) => + implicit val ctx: Context = ictx + val defn = ictx.definitions + + assertMessageCount(1, messages) + val CyclicReferenceInvolving(denot) :: Nil = messages + assertEquals("value x", denot.show) + } + @Test def cyclicReferenceInvolvingImplicit = checkMessagesAfter("frontend") { """ -- cgit v1.2.3 From 98465f930fe5d3f10401c454d6655da71243b923 Mon Sep 17 00:00:00 2001 From: Enno Runne Date: Tue, 7 Mar 2017 20:05:28 +0100 Subject: Analysis of overloaded or recursive is harder than expected Fall-back to reporting "overloaded or recursive needs type". --- .../dotc/reporting/diagnostic/ErrorMessageID.java | 3 +-- .../tools/dotc/reporting/diagnostic/messages.scala | 29 +++++++++------------- .../dotty/tools/dotc/typer/ErrorReporting.scala | 5 +--- .../tools/dotc/reporting/ErrorMessagesTests.scala | 6 ++--- 4 files changed, 17 insertions(+), 26 deletions(-) (limited to 'compiler') 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) } -- cgit v1.2.3