From ff2515415a1f5220bf2bdf5d6fcf95e9a19f2bb0 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Sun, 26 Nov 2017 22:16:40 +0100 Subject: [PATCH 1/9] #1589: Add error message for symbol with unparsable version number. RefCheck:694 --- .../reporting/diagnostic/ErrorMessageID.java | 1 + .../dotc/reporting/diagnostic/messages.scala | 21 +++++++++++++++++++ .../dotty/tools/dotc/typer/RefChecks.scala | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index 4f5ed0ef4ab6..c28378774347 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -118,6 +118,7 @@ public enum ErrorMessageID { StaticFieldsOnlyAllowedInObjectsID, CyclicInheritanceID, UnableToExtendSealedClassID, + SymbolHasUnparsableVersionNumberID, ; 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 94192d13ee57..29b69f4beba4 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1972,4 +1972,25 @@ object messages { val msg = hl"Cannot extend ${"sealed"} $pclazz in a different source file" val explanation = "A sealed class or trait can only be extended in the same file as its declaration" } + + case class SymbolHasUnparsableVersionNumber(symbol: Symbol, message: String)(implicit ctx: Context)extends Message(SymbolHasUnparsableVersionNumberID) { + val kind = "Syntax" + val msg = hl"${symbol.showLocated} has an unparsable version number: $message" + val explanation = { + val scalaVersionExample = + hl""" + |There was a problem parsing $message. + |Versions should be in the form major[.minor[.revision]] + |where each part is a positive number, as in 2.10.1. + |The minor and revision parts are optional + """.stripMargin + + hl"""$scalaVersionExample + | + |When a symbol is marked with ${"@migration"} indicating it has changed semantics + |between versions and the ${"-Xmigration"} settings is used to warn about constructs + |whose behavior may have changed since version, the version used in the annotation + |must be in a valid format.""".stripMargin + } + } } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 07164bc68f8d..b42fd4000e0a 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -691,7 +691,7 @@ object RefChecks { case scala.util.Success(v) => ctx.settings.Xmigration.value < v case Failure(ex) => - ctx.warning(s"${sym.showLocated} has an unparsable version number: ${ex.getMessage()}", pos) + ctx.warning(SymbolHasUnparsableVersionNumber(sym, ex.getMessage()), pos) false } if (changed) From 121ab58eb4dcbeb8311684ed256e5ec500041a8e Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Sun, 26 Nov 2017 22:43:12 +0100 Subject: [PATCH 2/9] #1589: Add error message for symbol has changed semantics in version. RefCheck:698 --- .../reporting/diagnostic/ErrorMessageID.java | 1 + .../dotc/reporting/diagnostic/messages.scala | 28 +++++++++++++++---- .../dotty/tools/dotc/typer/RefChecks.scala | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index c28378774347..e1a1bbe767bf 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -119,6 +119,7 @@ public enum ErrorMessageID { CyclicInheritanceID, UnableToExtendSealedClassID, SymbolHasUnparsableVersionNumberID, + SymbolChangedSemanticsInVersionID, ; 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 29b69f4beba4..4b69c336ec48 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -21,8 +21,10 @@ import ErrorMessageID._ import Denotations.SingleDenotation import dotty.tools.dotc.ast.Trees import dotty.tools.dotc.ast.untpd.Modifiers +import dotty.tools.dotc.config.ScalaVersion import dotty.tools.dotc.core.Flags.{FlagSet, Mutable} import dotty.tools.dotc.core.SymDenotations.SymDenotation + import scala.util.control.NonFatal object messages { @@ -140,7 +142,7 @@ object messages { } case class EmptyCatchBlock(tryBody: untpd.Tree)(implicit ctx: Context) - extends EmptyCatchOrFinallyBlock(tryBody, EmptyCatchBlockID) { + extends EmptyCatchOrFinallyBlock(tryBody, EmptyCatchBlockID) { val kind = "Syntax" val msg = hl"""|The ${"catch"} block does not contain a valid expression, try @@ -1973,7 +1975,8 @@ object messages { val explanation = "A sealed class or trait can only be extended in the same file as its declaration" } - case class SymbolHasUnparsableVersionNumber(symbol: Symbol, message: String)(implicit ctx: Context)extends Message(SymbolHasUnparsableVersionNumberID) { + case class SymbolHasUnparsableVersionNumber(symbol: Symbol, message: String)(implicit ctx: Context) + extends Message(SymbolHasUnparsableVersionNumberID) { val kind = "Syntax" val msg = hl"${symbol.showLocated} has an unparsable version number: $message" val explanation = { @@ -1987,10 +1990,25 @@ object messages { hl"""$scalaVersionExample | - |When a symbol is marked with ${"@migration"} indicating it has changed semantics + |The symbol is marked with ${"@migration"} indicating it has changed semantics + |between versions and the ${"-Xmigration"} settings is used to warn about constructs + |whose behavior may have changed since version.""".stripMargin + } + } + + case class SymbolChangedSemanticsInVersion( + symbol: Symbol, + symbolVersion: scala.util.Try[ScalaVersion], + migrationVersion: scala.util.Try[ScalaVersion] + )(implicit ctx: Context) extends Message(SymbolChangedSemanticsInVersionID) { + val kind = "Syntax" + val msg = + hl"""${symbol.showLocated} has changed semantics in version $symbolVersion: + |$migrationVersion""".stripMargin + val explanation = { + hl"""The symbol is marked with ${"@migration"} indicating it has changed semantics |between versions and the ${"-Xmigration"} settings is used to warn about constructs - |whose behavior may have changed since version, the version used in the annotation - |must be in a valid format.""".stripMargin + |whose behavior may have changed since version.""".stripMargin } } } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index b42fd4000e0a..c02a9c6bb52b 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -695,7 +695,7 @@ object RefChecks { false } if (changed) - ctx.warning(s"${sym.showLocated} has changed semantics in version $symVersion:\n${sym.migrationMessage.get}") + ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) } /* (Not enabled yet) * See an explanation of compileTimeOnly in its scaladoc at scala.annotation.compileTimeOnly. From 7a511b37383dda251f3228b88b399b266c81e961 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Sun, 26 Nov 2017 23:08:24 +0100 Subject: [PATCH 3/9] #1589: Reuse migration message . RefCheck:694 --- .../dotc/reporting/diagnostic/messages.scala | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 4b69c336ec48..12a0f7b90fa9 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1975,25 +1975,16 @@ object messages { val explanation = "A sealed class or trait can only be extended in the same file as its declaration" } - case class SymbolHasUnparsableVersionNumber(symbol: Symbol, message: String)(implicit ctx: Context) + case class SymbolHasUnparsableVersionNumber(symbol: Symbol, migrationMessage: String)(implicit ctx: Context) extends Message(SymbolHasUnparsableVersionNumberID) { val kind = "Syntax" - val msg = hl"${symbol.showLocated} has an unparsable version number: $message" - val explanation = { - val scalaVersionExample = - hl""" - |There was a problem parsing $message. - |Versions should be in the form major[.minor[.revision]] - |where each part is a positive number, as in 2.10.1. - |The minor and revision parts are optional - """.stripMargin - - hl"""$scalaVersionExample + val msg = hl"${symbol.showLocated} has an unparsable version number: $migrationMessage" + val explanation = + hl"""$migrationMessage | |The symbol is marked with ${"@migration"} indicating it has changed semantics |between versions and the ${"-Xmigration"} settings is used to warn about constructs |whose behavior may have changed since version.""".stripMargin - } } case class SymbolChangedSemanticsInVersion( From ae876efd67c360e2995f22209c34b1dfbe899627 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Sun, 26 Nov 2017 23:10:22 +0100 Subject: [PATCH 4/9] #1589: Remove empty line. --- .../src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 12a0f7b90fa9..d08d0f1a082f 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -24,7 +24,6 @@ import dotty.tools.dotc.ast.untpd.Modifiers import dotty.tools.dotc.config.ScalaVersion import dotty.tools.dotc.core.Flags.{FlagSet, Mutable} import dotty.tools.dotc.core.SymDenotations.SymDenotation - import scala.util.control.NonFatal object messages { From a7604e76d4e1e7066c0c26e2f9c50757e9604fb9 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Tue, 28 Nov 2017 20:34:46 +0100 Subject: [PATCH 5/9] Ref #1589: Updated error message explanation based on code review. --- .../dotty/tools/dotc/reporting/diagnostic/messages.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 9c3ce5bbfcfe..1420f22e718d 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1981,9 +1981,9 @@ object messages { val explanation = hl"""$migrationMessage | - |The symbol is marked with ${"@migration"} indicating it has changed semantics + |The ${symbol.showLocated} is marked with ${"@migration"} indicating it has changed semantics |between versions and the ${"-Xmigration"} settings is used to warn about constructs - |whose behavior may have changed since version.""".stripMargin + |whose behavior may have changed since version change.""".stripMargin } case class SymbolChangedSemanticsInVersion( @@ -1996,9 +1996,9 @@ object messages { hl"""${symbol.showLocated} has changed semantics in version $symbolVersion: |$migrationVersion""".stripMargin val explanation = { - hl"""The symbol is marked with ${"@migration"} indicating it has changed semantics + hl"""The ${symbol.showLocated} is marked with ${"@migration"} indicating it has changed semantics |between versions and the ${"-Xmigration"} settings is used to warn about constructs - |whose behavior may have changed since version.""".stripMargin + |whose behavior may have changed since version change.""".stripMargin } } From 33275a5570ab9de85fcee09595cb902097140002 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Tue, 28 Nov 2017 21:23:10 +0100 Subject: [PATCH 6/9] Ref #1589: Polishing. --- .../tools/dotc/reporting/diagnostic/messages.scala | 2 +- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 1420f22e718d..abd058e5e52b 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1988,7 +1988,7 @@ object messages { case class SymbolChangedSemanticsInVersion( symbol: Symbol, - symbolVersion: scala.util.Try[ScalaVersion], + symbolVersion: ScalaVersion, migrationVersion: scala.util.Try[ScalaVersion] )(implicit ctx: Context) extends Message(SymbolChangedSemanticsInVersionID) { val kind = "Syntax" diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index c02a9c6bb52b..d086895310e8 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -686,16 +686,13 @@ object RefChecks { // Similar to deprecation: check if the symbol is marked with @migration // indicating it has changed semantics between versions. if (sym.hasAnnotation(defn.MigrationAnnot) && ctx.settings.Xmigration.value != NoScalaVersion) { - val symVersion: scala.util.Try[ScalaVersion] = sym.migrationVersion.get - val changed = symVersion match { - case scala.util.Success(v) => - ctx.settings.Xmigration.value < v + sym.migrationVersion.get match { + case scala.util.Success(symVersion) => + ctx.settings.Xmigration.value < symVersion + ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) case Failure(ex) => ctx.warning(SymbolHasUnparsableVersionNumber(sym, ex.getMessage()), pos) - false } - if (changed) - ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) } /* (Not enabled yet) * See an explanation of compileTimeOnly in its scaladoc at scala.annotation.compileTimeOnly. From 6c11f680d940bb57db433ba1c9980a143d95384f Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Tue, 28 Nov 2017 21:28:49 +0100 Subject: [PATCH 7/9] Ref #1589: Polishing. --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index d086895310e8..8aeadc49e6d9 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -685,10 +685,10 @@ object RefChecks { } // Similar to deprecation: check if the symbol is marked with @migration // indicating it has changed semantics between versions. - if (sym.hasAnnotation(defn.MigrationAnnot) && ctx.settings.Xmigration.value != NoScalaVersion) { + val xMigrationValue = ctx.settings.Xmigration.value + if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) { sym.migrationVersion.get match { - case scala.util.Success(symVersion) => - ctx.settings.Xmigration.value < symVersion + case scala.util.Success(symVersion) if xMigrationValue < symVersion => ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) case Failure(ex) => ctx.warning(SymbolHasUnparsableVersionNumber(sym, ex.getMessage()), pos) From e5c2d918232bc4b16c830e8bd5a6ebf09fd53602 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Tue, 28 Nov 2017 21:41:48 +0100 Subject: [PATCH 8/9] Ref #1589: Polishing. --- .../tools/dotc/reporting/diagnostic/messages.scala | 11 ++++------- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 5 +++-- scala-backend | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index abd058e5e52b..112b01e43722 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1983,22 +1983,19 @@ object messages { | |The ${symbol.showLocated} is marked with ${"@migration"} indicating it has changed semantics |between versions and the ${"-Xmigration"} settings is used to warn about constructs - |whose behavior may have changed since version change.""".stripMargin + |whose behavior may have changed since version change.""" } case class SymbolChangedSemanticsInVersion( symbol: Symbol, - symbolVersion: ScalaVersion, - migrationVersion: scala.util.Try[ScalaVersion] + migrationVersion: ScalaVersion )(implicit ctx: Context) extends Message(SymbolChangedSemanticsInVersionID) { val kind = "Syntax" - val msg = - hl"""${symbol.showLocated} has changed semantics in version $symbolVersion: - |$migrationVersion""".stripMargin + val msg = hl"${symbol.showLocated} has changed semantics in version $migrationVersion" val explanation = { hl"""The ${symbol.showLocated} is marked with ${"@migration"} indicating it has changed semantics |between versions and the ${"-Xmigration"} settings is used to warn about constructs - |whose behavior may have changed since version change.""".stripMargin + |whose behavior may have changed since version change.""" } } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 8aeadc49e6d9..d09bd7ce03e7 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -688,10 +688,11 @@ object RefChecks { val xMigrationValue = ctx.settings.Xmigration.value if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) { sym.migrationVersion.get match { - case scala.util.Success(symVersion) if xMigrationValue < symVersion => - ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) + case scala.util.Success(symVersion) if xMigrationValue < symVersion=> + ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion), pos) case Failure(ex) => ctx.warning(SymbolHasUnparsableVersionNumber(sym, ex.getMessage()), pos) + case _ => () } } /* (Not enabled yet) diff --git a/scala-backend b/scala-backend index 9dfe905943d0..b4f91888b6e7 160000 --- a/scala-backend +++ b/scala-backend @@ -1 +1 @@ -Subproject commit 9dfe905943d0fc946677f75caf38d10915c185ae +Subproject commit b4f91888b6e778fd1ea0aee2dbf832ae8b59a48a From 3b8039eb9e0f205518370abb075e3e1c3fa07508 Mon Sep 17 00:00:00 2001 From: Vitor Vieira Date: Tue, 28 Nov 2017 22:17:26 +0100 Subject: [PATCH 9/9] Ref #1589: Polishing. --- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index d09bd7ce03e7..3df7168e30bf 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -692,7 +692,7 @@ object RefChecks { ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion), pos) case Failure(ex) => ctx.warning(SymbolHasUnparsableVersionNumber(sym, ex.getMessage()), pos) - case _ => () + case _ => } } /* (Not enabled yet)