-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Ref #1589: Add warning messages for migration annotation #3562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
ff25154
121ab58
7a511b3
ae876ef
cbcd621
a7604e7
33275a5
6c11f68
e5c2d91
3b8039e
435a5f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ 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 | ||
|
|
@@ -140,7 +141,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,6 +1974,34 @@ 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, migrationMessage: String)(implicit ctx: Context) | ||
| extends Message(SymbolHasUnparsableVersionNumberID) { | ||
| val kind = "Syntax" | ||
| val msg = hl"${symbol.showLocated} has an unparsable version number: $migrationMessage" | ||
| val explanation = | ||
| hl"""$migrationMessage | ||
| | | ||
| |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 | ||
| } | ||
|
|
||
| case class SymbolChangedSemanticsInVersion( | ||
| symbol: Symbol, | ||
| symbolVersion: 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.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 | ||
|
||
| } | ||
| } | ||
|
|
||
| case class UnableToEmitSwitch()(implicit ctx: Context) | ||
| extends Message(UnableToEmitSwitchID) { | ||
| val kind = "Syntax" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -685,17 +685,14 @@ 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 | ||
| val xMigrationValue = ctx.settings.Xmigration.value | ||
| if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) { | ||
| sym.migrationVersion.get match { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your match is not exhaustive
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
| case scala.util.Success(symVersion) if xMigrationValue < symVersion => | ||
| ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get)) | ||
|
||
| case Failure(ex) => | ||
| ctx.warning(s"${sym.showLocated} has an unparsable version number: ${ex.getMessage()}", pos) | ||
| false | ||
| ctx.warning(SymbolHasUnparsableVersionNumber(sym, ex.getMessage()), pos) | ||
| } | ||
| if (changed) | ||
| ctx.warning(s"${sym.showLocated} has changed semantics in version $symVersion:\n${sym.migrationMessage.get}") | ||
| } | ||
| /* (Not enabled yet) | ||
| * See an explanation of compileTimeOnly in its scaladoc at scala.annotation.compileTimeOnly. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to
stripMarginThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.