From 924f2d765641f9f4f432d8fe9471cf60a3c7e657 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 23 May 2022 14:07:17 +0200 Subject: [PATCH 1/3] Remove ErrorMessageID.LazyErrorId --- .../tools/dotc/reporting/ErrorMessageID.scala | 14 ++++----- .../dotc/reporting/TestMessageLaziness.scala | 29 ------------------- 2 files changed, 7 insertions(+), 36 deletions(-) delete mode 100644 compiler/test/dotty/tools/dotc/reporting/TestMessageLaziness.scala diff --git a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala index 0df893b7d6fd..45bf2e9096ba 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala @@ -6,7 +6,7 @@ package dotty.tools.dotc.reporting enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMessageID]: // IMPORTANT: Add new IDs only at the end and never remove IDs - case LazyErrorId // // errorNumber: -2 + case NoExplanationID // errorNumber: -1 case EmptyCatchOrFinallyBlockID extends ErrorMessageID(isActive = false) // errorNumber: 0 @@ -19,8 +19,8 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe case TypeMismatchID // errorNumber: 7 case NotAMemberID // errorNumber: 8 case EarlyDefinitionsNotSupportedID // errorNumber: 9 - case TopLevelImplicitClassID extends ErrorMessageID(isActive = false) // errorNumber: 10 - case ImplicitCaseClassID // errorNumber: 11 + case TopLevelImplicitClassID extends ErrorMessageID(isActive = false) // errorNumber: 10 + case ImplicitCaseClassID // errorNumber: 11 case ImplicitClassPrimaryConstructorArityID // errorNumber: 12 case ObjectMayNotHaveSelfTypeID // errorNumber: 13 case TupleTooLongID extends ErrorMessageID(isActive = false) // errorNumber: 14 @@ -97,7 +97,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe case FunctionTypeNeedsNonEmptyParameterListID // errorNumber: 85 case WrongNumberOfParametersID // errorNumber: 86 case DuplicatePrivateProtectedQualifierID // errorNumber: 87 - case ExpectedStartOfTopLevelDefinitionID // errorNumber: 88 + case ExpectedStartOfTopLevelDefinitionID // errorNumber: 88 case MissingReturnTypeWithReturnStatementID // errorNumber: 89 case NoReturnFromInlineableID // errorNumber: 90 case ReturnOutsideMethodDefinitionID // errorNumber: 91 @@ -180,12 +180,12 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe case ImplicitSearchTooLargeID // errorNumber: 168 case TargetNameOnTopLevelClassID // errorNumber: 169 - def errorNumber = ordinal - 2 + def errorNumber = ordinal - 1 object ErrorMessageID: def fromErrorNumber(n: Int): Option[ErrorMessageID] = - val enumId = n + 2 - if enumId >= 2 && enumId < ErrorMessageID.values.length then + val enumId = n + 1 + if enumId >= 1 && enumId < ErrorMessageID.values.length then Some(fromOrdinal(enumId)) else None diff --git a/compiler/test/dotty/tools/dotc/reporting/TestMessageLaziness.scala b/compiler/test/dotty/tools/dotc/reporting/TestMessageLaziness.scala deleted file mode 100644 index deae96d4168f..000000000000 --- a/compiler/test/dotty/tools/dotc/reporting/TestMessageLaziness.scala +++ /dev/null @@ -1,29 +0,0 @@ -package dotty.tools -package dotc -package reporting - -import org.junit.Test -import core.Contexts._ - -class TestMessageLaziness extends DottyTest { - ctx = ctx.fresh.setReporter(new NonchalantReporter) - - class NonchalantReporter(using Context) extends Reporter - with UniqueMessagePositions with HideNonSensicalMessages { - def doReport(dia: Diagnostic)(using Context) = ??? - - override def report(dia: Diagnostic)(using Context) = () - } - - case class LazyError() extends Message(ErrorMessageID.LazyErrorId) { - val kind = MessageKind.NoKind - def msg = throw new Error("Didn't stay lazy.") - def explain = "" - } - - @Test def assureLazy = - report.error(LazyError()) - - @Test def assureLazyExtendMessage = - report.errorOrMigrationWarning(LazyError(), from = config.SourceVersion.future) -} From 6563f6526c536be235a567d69a56af84b546aba8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 23 May 2022 14:24:54 +0200 Subject: [PATCH 2/3] Copy doc from `Message.errorId` to `ErrorMessageID` --- compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala | 3 ++- compiler/src/dotty/tools/dotc/reporting/Message.scala | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala index 45bf2e9096ba..b25eda3edfc1 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala @@ -1,6 +1,7 @@ package dotty.tools.dotc.reporting -/** Unique IDs identifying the messages +/** Unique IDs identifying the messages, this will be used to reference documentation online. + * * @param isActive Whether or not the compile still emits this ErrorMessageID **/ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMessageID]: diff --git a/compiler/src/dotty/tools/dotc/reporting/Message.scala b/compiler/src/dotty/tools/dotc/reporting/Message.scala index 830516a2ebfd..77e1336a990c 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Message.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Message.scala @@ -43,7 +43,7 @@ object Message { * Instead use the `persist` method to create an instance that does not keep a * reference to these contexts. * - * @param errorId a unique id identifying the message, this will later be + * @param errorId a unique id identifying the message, this will be * used to reference documentation online */ abstract class Message(val errorId: ErrorMessageID) { self => From 825d92e073b3cd4a614ce548a1273219fe4c5d0d Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 23 May 2022 14:28:00 +0200 Subject: [PATCH 3/3] Make constraints on error message IDs clearer --- .../src/dotty/tools/dotc/reporting/ErrorMessageID.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala index b25eda3edfc1..ea8ba39d73ca 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala @@ -1,13 +1,16 @@ package dotty.tools.dotc.reporting +////////////////////////////////////////////////////////////////////////// +// IMPORTANT // +// Only add new IDs at end of the enumeration list and never remove IDs // +////////////////////////////////////////////////////////////////////////// + /** Unique IDs identifying the messages, this will be used to reference documentation online. * * @param isActive Whether or not the compile still emits this ErrorMessageID **/ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMessageID]: - // IMPORTANT: Add new IDs only at the end and never remove IDs - case NoExplanationID // errorNumber: -1 case EmptyCatchOrFinallyBlockID extends ErrorMessageID(isActive = false) // errorNumber: 0