8000 Migration message and version cleanup · scala/scala@60b90b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 60b90b1

Browse files
committed
Migration message and version cleanup
The @migration annotation can now be used like @Deprecation. Old syntax is still supported, but deprecated. Improve wording and consistency of migration messages, migration warnings also print the version in which the change occurred now. Partially fixes SI-4990.
1 parent 332fec9 commit 60b90b1

26 files changed

+77
-138
lines changed

src/compiler/scala/reflect/internal/Symbols.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
494494
// string. So this needs attention. For now the fact that migration is
495495
// private[scala] ought to provide enough protection.
496496
def hasMigrationAnnotation = hasAnnotation(MigrationAnnotationClass)
497-
def migrationMessage = getAnnotation(MigrationAnnotationClass) flatMap { _.stringArg(2) }
498-
def migrationVersion = getAnnotation(MigrationAnnotationClass) map { version => version.intArg(0).get + "." + version.intArg(1).get }
497+
def migrationMessage = getAnnotation(MigrationAnnotationClass) flatMap { _.stringArg(0) }
498+
def migrationVersion = getAnnotation(MigrationAnnotationClass) flatMap { _.stringArg(1) }
499499
def elisionLevel = getAnnotation(ElidableMethodClass) flatMap { _.intArg(0) }
500500
def implicitNotFoundMsg = getAnnotation(ImplicitNotFoundClass) flatMap { _.stringArg(0) }
501501

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,10 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
12731273
* indicating it has changed semantics between versions.
12741274
*/
12751275
private def checkMigration(sym: Symbol, pos: Position) = {
1276-
for (msg <- sym.migrationMessage)
1277-
unit.warning(pos, sym.fullLocationString + " has changed semantics:\n" + msg)
1276+
if (sym.hasMigrationAnnotation)
1277+
unit.warning(pos, "%s has changed semantics in version %s:\n%s".format(
1278+
sym.fullLocationString, sym.migrationVersion.get, sym.migrationMessage.get)
1279+
)
12781280
}
12791281

12801282
private def lessAccessible(otherSym: Symbol, memberSym: Symbol): Boolean = (

src/library/scala/annotation/migration.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ package scala.annotation
1414
* reason or another retain the same name and type signature,
1515
* but some aspect of their behavior is different. An illustrative
1616
* examples is Stack.iterator, which reversed from LIFO to FIFO
17-
* order between scala 2.7 and 2.8.
17+
* order between Scala 2.7 and 2.8.
1818
*
19-
* The version numbers are to mark the scala major/minor release
20-
* version where the change took place.
19+
* @param message A message describing the change, which is emitted
20+
* by the compiler if the flag `-Xmigration` is set.
21+
*
22+
* @param changedIn The version, in which the behaviour change was
23+
* introduced.
2124
*
2225
* @since 2.8
2326
*/
24-
private[scala] final class migration(
25-
majorVersion: Int,
26-
minorVersion: Int,
27-
message: String)
28-
extends annotation.StaticAnnotation {}
27+
private[scala] final class migration(message: String, changedIn: String) extends annotation.StaticAnnotation {
28+
@deprecated("Use the constructor taking two Strings instead.", "2.10")
29+
def this(majorVersion: Int, minorVersion: Int, message: String) = this(message, majorVersion + "." + minorVersion)
30+
}

src/library/scala/collection/GenTraversableLike.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ trait GenTraversableLike[+A, +Repr] extends GenTraversableOnce[A] with Paralleli
123123
* @param bf $bfinfo
124124
* @return collection with intermediate results
125125
*/
126-
@migration(2, 9,
127-
"This scanRight definition has changed in 2.9.\n" +
128-
"The previous behavior can be reproduced with scanRight.reverse."
129-
)
126+
@migration("The behavior of `scanRight` has changed. The previous behavior can be reproduced with scanRight.reverse.", "2.9.0")
130127
def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
131128

132129
/** Applies a function `f` to all elements of this $coll.

src/library/scala/collection/GenTraversableViewLike.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ package scala.collection
1212
import generic._
1313
import mutable.{ Builder, ArrayBuffer }
1414
import TraversableView.NoBuilder
15-
import annotation.migration
16-
1715

1816

1917
trait GenTraversableViewLike[+A,

src/library/scala/collection/Iterator.scala

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
package scala.collection
1010

1111
import mutable.ArrayBuffer
12-
import annotation.{ tailrec, migration }
12+
import annotation.migration
1313
import immutable.Stream
1414

1515
/** The `Iterator` object provides various functions for creating specialized iterators.
@@ -52,7 +52,7 @@ object Iterator {
5252

5353
/** Creates iterator that produces the results of some element computation a number of times.
5454
*
55-
* @param n the number of elements returned by the iterator.
55+
* @param len the number of elements returned by the iterator.
5656
* @param elem the element computation
5757
* @return An iterator that produces the results of `n` evaluations of `elem`.
5858
*/
@@ -66,7 +66,7 @@ object Iterator {
6666

6767
/** Creates an iterator producing the values of a given function over a range of integer values starting from 0.
6868
*
69-
* @param n The number of elements returned by the iterator
69+
* @param end The number of elements returned by the iterator
7070
* @param f The function computing element values
7171
* @return An iterator that produces the values `f(0), ..., f(n -1)`.
7272
*/
@@ -410,10 +410,7 @@ trait Iterator[+A] extends TraversableOnce[A] {
410410
* which `pf` is defined the image `pf(x)`.
411411
* @note Reuse: $consumesAndProducesIterator
412412
*/
413-
@migration(2, 8,
414-
"This collect implementation bears no relationship to the one before 2.8.\n"+
415-
"The previous behavior can be reproduced with toSeq."
416-
)
413+
@migration("`collect` has changed. The previous behavior can be reproduced with `toSeq`.", "2.8.0")
417414
def collect[B](pf: PartialFunction[A, B]): Iterator[B] = {
418415
val self = buffered
419416
new AbstractIterator[B] {
@@ -1033,9 +1030,9 @@ trait Iterator[+A] extends TraversableOnce[A] {
10331030

10341031
/** Returns this iterator with patched values.
10351032
*
1036-
* @param from The start index from which to patch
1037-
* @param ps The iterator of patch values
1038-
* @param replaced The number of values in the original iterator that are replaced by the patch.
1033+
* @param from The start index from which to patch
1034+
* @param patchElems The iterator of patch values
1035+
* @param replaced The number of values in the original iterator that are replaced by the patch.
10391036
* @note Reuse: $consumesTwoAndProducesOneIterator
10401037
*/
10411038
def patch[B >: A](from: Int, patchElems: Iterator[B], replaced: Int): Iterator[B] = new AbstractIterator[B] {

src/library/scala/collection/MapLike.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ self =>
182182
*
183183
* @return the keys of this map as an iterable.
184184
*/
185-
@migration(2, 8, "As of 2.8, keys returns Iterable[A] rather than Iterator[A].")
185+
@migration("`keys` returns `Iterable[A]` rather than `Iterator[A]`.", "2.8.0")
186186
def keys: Iterable[A] = keySet
187187

188188
/** Collects all values of this map in an iterable collection.
189189
*
190190
* @return the values of this map as an iterable.
191191
*/
192-
@migration(2, 8, "As of 2.8, values returns Iterable[B] rather than Iterator[B].")
192+
@migration("`values` returns `Iterable[B]` rather than `Iterator[B]`.", "2.8.0")
193193
def values: Iterable[B] = new DefaultValuesIterable
194194

195195
/** The implementation class of the iterable returned by `values`.

src/library/scala/collection/SetLike.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ self =>
8989
// note: this is only overridden here to add the migration annotation,
9090
// which I hope to turn into an Xlint style warning as the migration aspect
9191
// is not central to its importance.
92-
@migration(2, 8, "Set.map now returns a Set, so it will discard duplicate values.")
92+
@migration("Set.map now returns a Set, so it will discard duplicate values.", "2.8.0")
9393
override def map[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That = super.map(f)(bf)
9494

9595
/** Tests if some element is contained in this set.

src/library/scala/collection/TraversableLike.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr]
390390
b.result
391391
}
392392

393-
@migration(2, 9,
394-
"This scanRight definition has changed in 2.9.\n" +
395-
"The previous behavior can be reproduced with scanRight.reverse."
396-
)
393+
@migration("The behavior of `scanRight` has changed. The previous behavior can be reproduced with scanRight.reverse.", "2.9.0")
397394
def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = {
398395
var scanned = List(z)
399396
var acc = z

src/library/scala/collection/TraversableViewLike.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,7 @@ trait TraversableViewLike[+A,
185185
override def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[This, B, That]): That =
186186
newForced(thisSeq.scanLeft(z)(op)).asInstanceOf[That]
187187

188-
@migration(2, 9,
189-
"This scanRight definition has changed in 2.9.\n" +
190-
"The previous behavior can be reproduced with scanRight.reverse."
191-
)
188+
@migration("The behavior of `scanRight` has changed. The previous behavior can be reproduced with scanRight.reverse.", "2.9.0")
192189
override def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[This, B, That]): That =
193190
newForced(thisSeq.scanRight(z)(op)).asInstanceOf[That]
194191

0 commit comments

Comments
 (0)
0