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. --- .../dotc/reporting/diagnostic/ErrorMessageID.java | 4 +++- .../tools/dotc/reporting/diagnostic/messages.scala | 26 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'compiler/src/dotty/tools/dotc/reporting') 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" -- cgit v1.2.3