summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-04-14 11:40:00 +0100
committerPaul Phillips <paulp@improving.org>2012-04-14 11:48:30 +0100
commit0b3b12fb29b8a4a624c4a0bb4520114f10599036 (patch)
treec0176b6e048369cd8f1297b2d39ec66216e8768a /src/library
parent3a2901da406f2478b5634b0636e56de9c4cd676d (diff)
downloadscala-0b3b12fb29b8a4a624c4a0bb4520114f10599036.tar.gz
scala-0b3b12fb29b8a4a624c4a0bb4520114f10599036.tar.bz2
scala-0b3b12fb29b8a4a624c4a0bb4520114f10599036.zip
Move primitive widening implicits to companions.
Take a 15-implicit load off Predef and put it where it belongs: on those brave souls who like their longs to get floaty by way of T.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/Byte.scala5
-rw-r--r--src/library/scala/Char.scala4
-rw-r--r--src/library/scala/Float.scala1
-rw-r--r--src/library/scala/Int.scala3
-rw-r--r--src/library/scala/Long.scala2
-rw-r--r--src/library/scala/Predef.scala48
-rw-r--r--src/library/scala/Short.scala4
7 files changed, 43 insertions, 24 deletions
diff --git a/src/library/scala/Byte.scala b/src/library/scala/Byte.scala
index f9c5f6003e..4e64b68bbc 100644
--- a/src/library/scala/Byte.scala
+++ b/src/library/scala/Byte.scala
@@ -622,5 +622,10 @@ object Byte extends AnyValCompanion {
/** The String representation of the scala.Byte companion object.
*/
override def toString = "object scala.Byte"
+ implicit def byte2short(x: Byte): Short = x.toShort
+ implicit def byte2int(x: Byte): Int = x.toInt
+ implicit def byte2long(x: Byte): Long = x.toLong
+ implicit def byte2float(x: Byte): Float = x.toFloat
+ implicit def byte2double(x: Byte): Double = x.toDouble
}
diff --git a/src/library/scala/Char.scala b/src/library/scala/Char.scala
index 3d459782cd..8f770316c1 100644
--- a/src/library/scala/Char.scala
+++ b/src/library/scala/Char.scala
@@ -622,5 +622,9 @@ object Char extends AnyValCompanion {
/** The String representation of the scala.Char companion object.
*/
override def toString = "object scala.Char"
+ implicit def char2int(x: Char): Int = x.toInt
+ implicit def char2long(x: Char): Long = x.toLong
+ implicit def char2float(x: Char): Float = x.toFloat
+ implicit def char2double(x: Char): Double = x.toDouble
}
diff --git a/src/library/scala/Float.scala b/src/library/scala/Float.scala
index ff5b3cb112..ddbbd48bf4 100644
--- a/src/library/scala/Float.scala
+++ b/src/library/scala/Float.scala
@@ -401,5 +401,6 @@ object Float extends AnyValCompanion {
/** The String representation of the scala.Float companion object.
*/
override def toString = "object scala.Float"
+ implicit def float2double(x: Float): Double = x.toDouble
}
diff --git a/src/library/scala/Int.scala b/src/library/scala/Int.scala
index 316bbced2d..ef82b1f979 100644
--- a/src/library/scala/Int.scala
+++ b/src/library/scala/Int.scala
@@ -622,5 +622,8 @@ object Int extends AnyValCompanion {
/** The String representation of the scala.Int companion object.
*/
override def toString = "object scala.Int"
+ implicit def int2long(x: Int): Long = x.toLong
+ implicit def int2float(x: Int): Float = x.toFloat
+ implicit def int2double(x: Int): Double = x.toDouble
}
diff --git a/src/library/scala/Long.scala b/src/library/scala/Long.scala
index ce8618c22a..d57fe8b379 100644
--- a/src/library/scala/Long.scala
+++ b/src/library/scala/Long.scala
@@ -622,5 +622,7 @@ object Long extends AnyValCompanion {
/** The String representation of the scala.Long companion object.
*/
override def toString = "object scala.Long"
+ implicit def long2float(x: Long): Float = x.toFloat
+ implicit def long2double(x: Long): Double = x.toDouble
}
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala
index 0954454e41..15e007528b 100644
--- a/src/library/scala/Predef.scala
+++ b/src/library/scala/Predef.scala
@@ -349,30 +349,30 @@ object Predef extends LowPriorityImplicits {
// Primitive Widenings --------------------------------------------------------------
- implicit def byte2short(x: Byte): Short = x.toShort
- implicit def byte2int(x: Byte): Int = x.toInt
- implicit def byte2long(x: Byte): Long = x.toLong
- implicit def byte2float(x: Byte): Float = x.toFloat
- implicit def byte2double(x: Byte): Double = x.toDouble
-
- implicit def short2int(x: Short): Int = x.toInt
- implicit def short2long(x: Short): Long = x.toLong
- implicit def short2float(x: Short): Float = x.toFloat
- implicit def short2double(x: Short): Double = x.toDouble
-
- implicit def char2int(x: Char): Int = x.toInt
- implicit def char2long(x: Char): Long = x.toLong
- implicit def char2float(x: Char): Float = x.toFloat
- implicit def char2double(x: Char): Double = x.toDouble
-
- implicit def int2long(x: Int): Long = x.toLong
- implicit def int2float(x: Int): Float = x.toFloat
- implicit def int2double(x: Int): Double = x.toDouble
-
- implicit def long2float(x: Long): Float = x.toFloat
- implicit def long2double(x: Long): Double = x.toDouble
-
- implicit def float2double(x: Float): Double = x.toDouble
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def byte2short(x: Byte): Short = x.toShort
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def byte2int(x: Byte): Int = x.toInt
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def byte2long(x: Byte): Long = x.toLong
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def byte2float(x: Byte): Float = x.toFloat
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def byte2double(x: Byte): Double = x.toDouble
+
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def short2int(x: Short): Int = x.toInt
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def short2long(x: Short): Long = x.toLong
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def short2float(x: Short): Float = x.toFloat
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def short2double(x: Short): Double = x.toDouble
+
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def char2int(x: Char): Int = x.toInt
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def char2long(x: Char): Long = x.toLong
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def char2float(x: Char): Float = x.toFloat
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def char2double(x: Char): Double = x.toDouble
+
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def int2long(x: Int): Long = x.toLong
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def int2float(x: Int): Float = x.toFloat
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def int2double(x: Int): Double = x.toDouble
+
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def long2float(x: Long): Float = x.toFloat
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def long2double(x: Long): Double = x.toDouble
+
+ @deprecated("Use a method in an AnyVal's companion object", "2.10.0") def float2double(x: Float): Double = x.toDouble
// "Autoboxing" and "Autounboxing" ---------------------------------------------------
diff --git a/src/library/scala/Short.scala b/src/library/scala/Short.scala
index 5664c3b44c..707f9bc4eb 100644
--- a/src/library/scala/Short.scala
+++ b/src/library/scala/Short.scala
@@ -622,5 +622,9 @@ object Short extends AnyValCompanion {
/** The String representation of the scala.Short companion object.
*/
override def toString = "object scala.Short"
+ implicit def short2int(x: Short): Int = x.toInt
+ implicit def short2long(x: Short): Long = x.toLong
+ implicit def short2float(x: Short): Float = x.toFloat
+ implicit def short2double(x: Short): Double = x.toDouble
}