From 4eae7511a297b9d51e1aea2da38c5dacf786efa0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 22 Feb 2012 23:05:26 +0100 Subject: Compiler now ready to accept value classes in standard library. Time for a new STARR! --- src/library/scala/runtime/StringAdd.scala | 7 +++++++ src/library/scala/runtime/StringFormat.scala | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/library') diff --git a/src/library/scala/runtime/StringAdd.scala b/src/library/scala/runtime/StringAdd.scala index a1256c3f3b..a7e78ea9a3 100644 --- a/src/library/scala/runtime/StringAdd.scala +++ b/src/library/scala/runtime/StringAdd.scala @@ -8,8 +8,15 @@ package scala.runtime +/** A wrapper class that adds string concatenation `+` to any value */ final class StringAdd(val self: Any) { + // Note: The implicit conversion from Any to StringAdd is one of two + // implicit conversions from Any to AnyRef in Predef. It is important to have at least + // two such conversions, so that silent conversions from value types to AnyRef + // are avoided. If StringFormat should become a value class, another + // implicit conversion from Any to AnyRef has to be introduced in Predef + def +(other: String) = String.valueOf(self) + other } diff --git a/src/library/scala/runtime/StringFormat.scala b/src/library/scala/runtime/StringFormat.scala index 94bba4043c..1f0183afbb 100644 --- a/src/library/scala/runtime/StringFormat.scala +++ b/src/library/scala/runtime/StringFormat.scala @@ -8,7 +8,15 @@ package scala.runtime -final class StringFormat(val self: Any) extends AnyVal { +/** A wrapper class that adds a `formatted` operation to any value + */ +final class StringFormat(val self: Any) { + + // Note: The implicit conversion from Any to StringFormat is one of two + // implicit conversions from Any to AnyRef in Predef. It is important to have at least + // two such conversions, so that silent conversions from value types to AnyRef + // are avoided. If StringFormat should become a value class, another + // implicit conversion from Any to AnyRef has to be introduced in Predef /** Returns string formatted according to given `format` string. * Format strings are as for `String.format` -- cgit v1.2.3