Skip to content

Commit 0ec9475

Browse files
committed
Deprecate +(x: String): String on primitives
This is consistent with the deprecation of any2stringadd in scala#6315.
1 parent 235e69d commit 0ec9475

26 files changed

+69
-57
lines changed

project/GenerateAnyVals.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ import scala.language.implicitConversions"""
146146

147147
def mkCoercions = numeric map (x => "def to%s: %s".format(x, x))
148148
def mkUnaryOps = unaryOps map (x => "%s\n def unary_%s : %s".format(x.doc, x.op, this opType I))
149-
def mkStringOps = List("def +(x: String): String")
149+
def mkStringOps = List(
150+
"""@deprecated("Adding a number and a String is deprecated. Convert the number to a String with `toString` first to call +", "2.13.0") def +(x: String): String"""
151+
)
150152
def mkShiftOps = (
151153
for (op <- shiftOps ; arg <- List(I, L)) yield
152154
"%s\n def %s(x: %s): %s".format(op.doc, op.op, arg, this opType I)

src/library/scala/Byte.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final abstract class Byte private extends AnyVal {
4242
/** Returns the negation of this value. */
4343
def unary_- : Int
4444

45-
def +(x: String): String
45+
@deprecated("Adding a number and a String is deprecated. Convert the number to a String with `toString` first to call +", "2.13.0") def +(x: String): String
4646

4747
/**
4848
* Returns this value bit-shifted left by the specified number of bits,

src/library/scala/Char.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final abstract class Char private extends AnyVal {
4242
/** Returns the negation of this value. */
4343
def unary_- : Int
4444

45-
def +(x: String): String
45+
@deprecated("Adding a number and a String is deprecated. Convert the number to a String with `toString` first to call +", "2.13.0") def +(x: String): String
4646

4747
/**
4848
* Returns this value bit-shifted left by the specified number of bits,

src/library/scala/Double.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final abstract class Double private extends AnyVal {
3333
/** Returns the negation of this value. */
3434
def unary_- : Double
3535

36-
def +(x: String): String
36+
@deprecated("Adding a number and a String is deprecated. Convert the number to a String with `toString` first to call +", "2.13.0") def +(x: String): String
3737

3838
/** Returns `true` if this value is equal to x, `false` otherwise. */
3939
def ==(x: Byte): Boolean

src/library/scala/Float.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final abstract class Float private extends AnyVal {
3333
/** Returns the negation of this value. */
3434
def unary_- : Float
3535

36-
def +(x: String): String
36+
@deprecated("Adding a number and a String is deprecated. Convert the number to a String with `toString` first to call +", "2.13.0") def +(x: String): String
3737

3838
/** Returns `true` if this value is equal to x, `false` otherwise. */
3939
def ==(x: Byte): Boolean

src/library/scala/Int.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final abstract class Int private extends AnyVal {
4242
/** Returns the negation of this value. */
4343
def unary_- : Int
4444

45-
def +(x: String): String
45+
@deprecated("Adding a number and a String is deprecated. Convert the number to a String with `toString` first to call +", "2.13.0") def +(x: String): String
4646

4747
/**
4848
* Returns this value bit-shifted left by the specified number of bits,

src/library/scala/Long.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final abstract class Long private extends AnyVal {
4242
/** Returns the negation of this value. */
4343
def unary_- : Long
4444

45-
def +(x: String): String
45+
@deprecated("Adding a number and a String is deprecated. Convert the number to a String with `toString` first to call +", "2.13.0") def +(x: String): String
4646

4747
/**
4848
* Returns this value bit-shifted left by the specified number of bits,

src/library/scala/Short.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final abstract class Short private extends AnyVal {
4242
/** Returns the negation of this value. */
4343
def unary_- : Int
4444

45-
def +(x: String): String
45+
@deprecated("Adding a number and a String is deprecated. Convert the number to a String with `toString` first to call +", "2.13.0") def +(x: String): String
4646

4747
/**
4848
* Returns this value bit-shifted left by the specified number of bits,

test/files/jvm/duration-tck.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ object Test extends App {
151151
intercept[IllegalArgumentException] { mdur / 0.9 }
152152
intercept[IllegalArgumentException] { dur / 0.4 }
153153
intercept[IllegalArgumentException] { mdur / 0.4 }
154-
Duration(x + unit.toString.toLowerCase)
154+
Duration(x.toString + unit.toString.toLowerCase)
155155
Duration("-" + x + unit.toString.toLowerCase)
156156
intercept[IllegalArgumentException] { Duration("%.0f".format(x + 10000000d) + unit.toString.toLowerCase) }
157157
intercept[IllegalArgumentException] { Duration("-%.0f".format(x + 10000000d) + unit.toString.toLowerCase) }

test/files/jvm/sync-var.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ summers foreach { _.join() }
4444

4545
val got = sum.get
4646
val expected = (n + 1) * n / 2
47-
println(got + " " + expected + " " + (got == expected))
47+
println(got.toString + " " + expected + " " + (got == expected))
4848

4949
producers foreach { _.join() }
5050

0 commit comments

Comments
 (0)