Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public enum ErrorMessageID {
StaticFieldsOnlyAllowedInObjectsID,
CyclicInheritanceID,
UnableToExtendSealedClassID,
SymbolHasUnparsableVersionNumberID,
SymbolChangedSemanticsInVersionID,
UnableToEmitSwitchID,
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor

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 stripMargin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

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
Copy link
Contributor

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 stripMargin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}
}

case class UnableToEmitSwitch()(implicit ctx: Context)
extends Message(UnableToEmitSwitchID) {
val kind = "Syntax"
Expand Down
15 changes: 6 additions & 9 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your match is not exhaustive

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove sym.migrationMessage.get. It is the same as symVersion. I don't know why it was duplicated in the first place

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have to change the final message if that is ok. Currently:

${symbol.showLocated} has changed semantics in version $symbolVersion:
$migrationVersion

The migrationMessage provides either a version string or an error message from ScalaVersion.parse:

 def failure = Failure(new NumberFormatException(
      s"There was a problem parsing ${versionString}. " +
       "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."
    ))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cannot be a failure since you're in the Success case of the match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing the pos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

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.
Expand Down