summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/cmd/gen/AnyVals.scala
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/compiler/scala/tools/cmd/gen/AnyVals.scala
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/compiler/scala/tools/cmd/gen/AnyVals.scala')
-rw-r--r--src/compiler/scala/tools/cmd/gen/AnyVals.scala16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala
index 0869350dd3..b9f1ee2317 100644
--- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala
+++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala
@@ -14,6 +14,20 @@ trait AnyValReps {
sealed abstract class AnyValNum(name: String, repr: Option[String], javaEquiv: String) extends AnyValRep(name,repr,javaEquiv) {
case class Op(val op : String, val doc : String)
+
+ private def companionCoercions(tos: String*) = {
+ tos.toList map (to =>
+ """implicit def %s2%s(x: %s): %s = x.to%s""".format(javaEquiv, to, name, to.capitalize, to.capitalize)
+ )
+ }
+ def implicitCoercions: List[String] = javaEquiv match {
+ case "byte" => companionCoercions("short", "int", "long", "float", "double")
+ case "short" | "char" => companionCoercions("int", "long", "float", "double")
+ case "int" => companionCoercions("long", "float", "double")
+ case "long" => companionCoercions("float", "double")
+ case "float" => companionCoercions("double")
+ case _ => Nil
+ }
def isCardinal: Boolean = isIntegerType(this)
def unaryOps = {
@@ -160,7 +174,7 @@ trait AnyValReps {
}
def objectLines = {
val comp = if (isCardinal) cardinalCompanion else floatingCompanion
- (comp + allCompanions).trim.lines map interpolate toList
+ ((comp + allCompanions).trim.lines map interpolate).toList ++ implicitCoercions
}
/** Makes a set of binary operations based on the given set of ops, args, and resultFn.