diff options
27 files changed, 140 insertions, 130 deletions
diff --git a/src/library/scala/LowPriorityImplicits.scala b/src/library/scala/LowPriorityImplicits.scala index 491cd417a3..8c49d2f67b 100644 --- a/src/library/scala/LowPriorityImplicits.scala +++ b/src/library/scala/LowPriorityImplicits.scala @@ -27,15 +27,20 @@ class LowPriorityImplicits { * any potential conflicts. Conflicts do exist because the wrappers * need to implement ScalaNumber in order to have a symmetric equals * method, but that implies implementing java.lang.Number as well. + * + * Note - these are inlined because they are value classes, but + * the call to xxxWrapper is not eliminated even though it does nothing. + * Even inlined, every call site does a no-op retrieval of Predef's MODULE$ + * because maybe loading Predef has side effects! */ - implicit def byteWrapper(x: Byte) = new runtime.RichByte(x) - implicit def shortWrapper(x: Short) = new runtime.RichShort(x) - implicit def intWrapper(x: Int) = new runtime.RichInt(x) - implicit def charWrapper(c: Char) = new runtime.RichChar(c) - implicit def longWrapper(x: Long) = new runtime.RichLong(x) - implicit def floatWrapper(x: Float) = new runtime.RichFloat(x) - implicit def doubleWrapper(x: Double) = new runtime.RichDouble(x) - implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x) + @inline implicit def byteWrapper(x: Byte) = new runtime.RichByte(x) + @inline implicit def shortWrapper(x: Short) = new runtime.RichShort(x) + @inline implicit def intWrapper(x: Int) = new runtime.RichInt(x) + @inline implicit def charWrapper(c: Char) = new runtime.RichChar(c) + @inline implicit def longWrapper(x: Long) = new runtime.RichLong(x) + @inline implicit def floatWrapper(x: Float) = new runtime.RichFloat(x) + @inline implicit def doubleWrapper(x: Double) = new runtime.RichDouble(x) + @inline implicit def booleanWrapper(x: Boolean) = new runtime.RichBoolean(x) // These eight implicits exist solely to exclude Null from the domain of // the boxed types, so that e.g. "var x: Int = null" is a compile time diff --git a/src/library/scala/collection/CustomParallelizable.scala b/src/library/scala/collection/CustomParallelizable.scala index dc634c67d3..a56cb5da59 100644 --- a/src/library/scala/collection/CustomParallelizable.scala +++ b/src/library/scala/collection/CustomParallelizable.scala @@ -10,7 +10,7 @@ package scala.collection import parallel.Combiner -trait CustomParallelizable[+A, +ParRepr <: Parallel] extends Parallelizable[A, ParRepr] { +trait CustomParallelizable[+A, +ParRepr <: Parallel] extends Any with Parallelizable[A, ParRepr] { override def par: ParRepr override protected[this] def parCombiner: Combiner[A, ParRepr] = throw new UnsupportedOperationException("") } diff --git a/src/library/scala/collection/mutable/ArrayLike.scala b/src/library/scala/collection/mutable/ArrayLike.scala index 04601845c4..172993c5c3 100644 --- a/src/library/scala/collection/mutable/ArrayLike.scala +++ b/src/library/scala/collection/mutable/ArrayLike.scala @@ -22,7 +22,7 @@ import generic._ * @version 2.8 * @since 2.8 */ -trait ArrayLike[A, +Repr] extends IndexedSeqOptimized[A, Repr] { self => +trait ArrayLike[A, +Repr] extends Any with IndexedSeqOptimized[A, Repr] { self => /** Creates a possible nested `IndexedSeq` which consists of all the elements * of this array. If the elements are arrays themselves, the `deep` transformation diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala index 21c2aaaec7..b3cd6a95c5 100644 --- a/src/library/scala/collection/mutable/ArrayOps.scala +++ b/src/library/scala/collection/mutable/ArrayOps.scala @@ -6,18 +6,14 @@ ** |/ ** \* */ - - package scala.collection package mutable -import compat.Platform.arraycopy +import compat.Platform.arraycopy import scala.reflect.ClassTag import scala.runtime.ScalaRunTime._ - import parallel.mutable.ParArray - /** This class serves as a wrapper for `Array`s with all the operations found in * indexed sequences. Where needed, instances of arrays are implicitly converted * into this class. @@ -36,7 +32,7 @@ import parallel.mutable.ParArray * @define mayNotTerminateInf * @define willNotTerminateInf */ -abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParallelizable[T, ParArray[T]] { +trait ArrayOps[T] extends Any with ArrayLike[T, Array[T]] with CustomParallelizable[T, ParArray[T]] { private def elementClass: Class[_] = arrayElementClass(repr.getClass) @@ -105,7 +101,7 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] with CustomParalleliza object ArrayOps { /** A class of `ArrayOps` for arrays containing reference types. */ - class ofRef[T <: AnyRef](override val repr: Array[T]) extends ArrayOps[T] with ArrayLike[T, Array[T]] { + final class ofRef[T <: AnyRef](override val repr: Array[T]) extends AnyVal with ArrayOps[T] with ArrayLike[T, Array[T]] { override protected[this] def thisCollection: WrappedArray[T] = new WrappedArray.ofRef[T](repr) override protected[this] def toCollection(repr: Array[T]): WrappedArray[T] = new WrappedArray.ofRef[T](repr) @@ -117,7 +113,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays containing `byte`s. */ - class ofByte(override val repr: Array[Byte]) extends ArrayOps[Byte] with ArrayLike[Byte, Array[Byte]] { +final class ofByte(override val repr: Array[Byte]) extends AnyVal with ArrayOps[Byte] with ArrayLike[Byte, Array[Byte]] { override protected[this] def thisCollection: WrappedArray[Byte] = new WrappedArray.ofByte(repr) override protected[this] def toCollection(repr: Array[Byte]): WrappedArray[Byte] = new WrappedArray.ofByte(repr) @@ -129,7 +125,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays containing `short`s. */ - class ofShort(override val repr: Array[Short]) extends ArrayOps[Short] with ArrayLike[Short, Array[Short]] { +final class ofShort(override val repr: Array[Short]) extends AnyVal with ArrayOps[Short] with ArrayLike[Short, Array[Short]] { override protected[this] def thisCollection: WrappedArray[Short] = new WrappedArray.ofShort(repr) override protected[this] def toCollection(repr: Array[Short]): WrappedArray[Short] = new WrappedArray.ofShort(repr) @@ -141,7 +137,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays containing `char`s. */ - class ofChar(override val repr: Array[Char]) extends ArrayOps[Char] with ArrayLike[Char, Array[Char]] { +final class ofChar(override val repr: Array[Char]) extends AnyVal with ArrayOps[Char] with ArrayLike[Char, Array[Char]] { override protected[this] def thisCollection: WrappedArray[Char] = new WrappedArray.ofChar(repr) override protected[this] def toCollection(repr: Array[Char]): WrappedArray[Char] = new WrappedArray.ofChar(repr) @@ -153,7 +149,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays containing `int`s. */ - class ofInt(override val repr: Array[Int]) extends ArrayOps[Int] with ArrayLike[Int, Array[Int]] { +final class ofInt(override val repr: Array[Int]) extends AnyVal with ArrayOps[Int] with ArrayLike[Int, Array[Int]] { override protected[this] def thisCollection: WrappedArray[Int] = new WrappedArray.ofInt(repr) override protected[this] def toCollection(repr: Array[Int]): WrappedArray[Int] = new WrappedArray.ofInt(repr) @@ -165,7 +161,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays containing `long`s. */ - class ofLong(override val repr: Array[Long]) extends ArrayOps[Long] with ArrayLike[Long, Array[Long]] { +final class ofLong(override val repr: Array[Long]) extends AnyVal with ArrayOps[Long] with ArrayLike[Long, Array[Long]] { override protected[this] def thisCollection: WrappedArray[Long] = new WrappedArray.ofLong(repr) override protected[this] def toCollection(repr: Array[Long]): WrappedArray[Long] = new WrappedArray.ofLong(repr) @@ -177,7 +173,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays containing `float`s. */ - class ofFloat(override val repr: Array[Float]) extends ArrayOps[Float] with ArrayLike[Float, Array[Float]] { +final class ofFloat(override val repr: Array[Float]) extends AnyVal with ArrayOps[Float] with ArrayLike[Float, Array[Float]] { override protected[this] def thisCollection: WrappedArray[Float] = new WrappedArray.ofFloat(repr) override protected[this] def toCollection(repr: Array[Float]): WrappedArray[Float] = new WrappedArray.ofFloat(repr) @@ -189,7 +185,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays containing `double`s. */ - class ofDouble(override val repr: Array[Double]) extends ArrayOps[Double] with ArrayLike[Double, Array[Double]] { +final class ofDouble(override val repr: Array[Double]) extends AnyVal with ArrayOps[Double] with ArrayLike[Double, Array[Double]] { override protected[this] def thisCollection: WrappedArray[Double] = new WrappedArray.ofDouble(repr) override protected[this] def toCollection(repr: Array[Double]): WrappedArray[Double] = new WrappedArray.ofDouble(repr) @@ -201,7 +197,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays containing `boolean`s. */ - class ofBoolean(override val repr: Array[Boolean]) extends ArrayOps[Boolean] with ArrayLike[Boolean, Array[Boolean]] { +final class ofBoolean(override val repr: Array[Boolean]) extends AnyVal with ArrayOps[Boolean] with ArrayLike[Boolean, Array[Boolean]] { override protected[this] def thisCollection: WrappedArray[Boolean] = new WrappedArray.ofBoolean(repr) override protected[this] def toCollection(repr: Array[Boolean]): WrappedArray[Boolean] = new WrappedArray.ofBoolean(repr) @@ -213,7 +209,7 @@ object ArrayOps { } /** A class of `ArrayOps` for arrays of `Unit` types. */ - class ofUnit(override val repr: Array[Unit]) extends ArrayOps[Unit] with ArrayLike[Unit, Array[Unit]] { +final class ofUnit(override val repr: Array[Unit]) extends AnyVal with ArrayOps[Unit] with ArrayLike[Unit, Array[Unit]] { override protected[this] def thisCollection: WrappedArray[Unit] = new WrappedArray.ofUnit(repr) override protected[this] def toCollection(repr: Array[Unit]): WrappedArray[Unit] = new WrappedArray.ofUnit(repr) diff --git a/src/library/scala/collection/mutable/IndexedSeqLike.scala b/src/library/scala/collection/mutable/IndexedSeqLike.scala index 5d4b4de7b2..b3fe95ef27 100644 --- a/src/library/scala/collection/mutable/IndexedSeqLike.scala +++ b/src/library/scala/collection/mutable/IndexedSeqLike.scala @@ -36,7 +36,7 @@ import generic._ * @define willNotTerminateInf * @define mayNotTerminateInf */ -trait IndexedSeqLike[A, +Repr] extends scala.collection.IndexedSeqLike[A, Repr] { self => +trait IndexedSeqLike[A, +Repr] extends Any with scala.collection.IndexedSeqLike[A, Repr] { self => override protected[this] def thisCollection: IndexedSeq[A] = this.asInstanceOf[IndexedSeq[A]] override protected[this] def toCollection(repr: Repr): IndexedSeq[A] = repr.asInstanceOf[IndexedSeq[A]] diff --git a/src/library/scala/collection/mutable/IndexedSeqOptimized.scala b/src/library/scala/collection/mutable/IndexedSeqOptimized.scala index 819d06476a..506d2d6736 100755 --- a/src/library/scala/collection/mutable/IndexedSeqOptimized.scala +++ b/src/library/scala/collection/mutable/IndexedSeqOptimized.scala @@ -17,4 +17,4 @@ import generic._ * * @since 2.8 */ -trait IndexedSeqOptimized[A, +Repr] extends IndexedSeqLike[A, Repr] with scala.collection.IndexedSeqOptimized[A, Repr] +trait IndexedSeqOptimized[A, +Repr] extends Any with IndexedSeqLike[A, Repr] with scala.collection.IndexedSeqOptimized[A, Repr] diff --git a/src/library/scala/math/BigDecimal.scala b/src/library/scala/math/BigDecimal.scala index 74daa510ca..8669b2e2e8 100644 --- a/src/library/scala/math/BigDecimal.scala +++ b/src/library/scala/math/BigDecimal.scala @@ -211,7 +211,7 @@ extends ScalaNumber with ScalaNumericConversions with Serializable { catch { case _: ArithmeticException => false } } - protected[math] def isWhole = (this remainder 1) == BigDecimal(0) + def isWhole() = (this remainder 1) == BigDecimal(0) def underlying = bigDecimal /** Compares this BigDecimal with the specified BigDecimal for equality. diff --git a/src/library/scala/math/BigInt.scala b/src/library/scala/math/BigInt.scala index 4471e417d9..09e8ae2026 100644 --- a/src/library/scala/math/BigInt.scala +++ b/src/library/scala/math/BigInt.scala @@ -162,7 +162,7 @@ class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNumericCo } /** Some implementations of java.math.BigInteger allow huge values with bit length greater than Int.MaxValue . * The BigInteger.bitLength method returns truncated bit length in this case . - * This method tests if result of bitLength is valid. + * This method tests if result of bitLength is valid. * This method will become unnecessary if BigInt constructors reject huge BigIntegers. */ private def bitLengthOverflow = { @@ -170,7 +170,7 @@ class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNumericCo (shifted.signum != 0) && !(shifted equals BigInt.minusOne) } - protected[math] def isWhole = true + def isWhole() = true def underlying = bigInteger /** Compares this BigInt with the specified BigInt for equality. diff --git a/src/library/scala/math/ScalaNumericConversions.scala b/src/library/scala/math/ScalaNumericConversions.scala index 2b7ef7405c..edf243e5df 100644 --- a/src/library/scala/math/ScalaNumericConversions.scala +++ b/src/library/scala/math/ScalaNumericConversions.scala @@ -13,7 +13,17 @@ import java.{ lang => jl } /** Conversions which present a consistent conversion interface * across all the numeric types. */ -trait ScalaNumericConversions extends ScalaNumber { +trait ScalaNumericConversions extends Any { + def isWhole(): Boolean + def underlying(): Any + + def byteValue(): Byte = intValue().toByte + def shortValue(): Short = intValue().toShort + def intValue(): Int + def longValue(): Long + def floatValue(): Float + def doubleValue(): Double + /** Returns the value of this as a [[scala.Char]]. This may involve * rounding or truncation. */ diff --git a/src/library/scala/runtime/RichBoolean.scala b/src/library/scala/runtime/RichBoolean.scala index a14160a71e..92cc6ccf98 100644 --- a/src/library/scala/runtime/RichBoolean.scala +++ b/src/library/scala/runtime/RichBoolean.scala @@ -8,6 +8,6 @@ package scala.runtime -final class RichBoolean(val self: Boolean) extends OrderedProxy[Boolean] { - protected val ord = math.Ordering[Boolean] +final class RichBoolean(val self: Boolean) extends AnyVal with OrderedProxy[Boolean] { + protected def ord = scala.math.Ordering.Boolean } diff --git a/src/library/scala/runtime/RichByte.scala b/src/library/scala/runtime/RichByte.scala index c42a2dd183..9d88ed3689 100644 --- a/src/library/scala/runtime/RichByte.scala +++ b/src/library/scala/runtime/RichByte.scala @@ -8,4 +8,7 @@ package scala.runtime -final class RichByte(val self: Byte) extends ScalaWholeNumberProxy[Byte] { } +final class RichByte(val self: Byte) extends AnyVal with ScalaWholeNumberProxy[Byte] { + protected def num = scala.math.Numeric.ByteIsIntegral + protected def ord = scala.math.Ordering.Byte +} diff --git a/src/library/scala/runtime/RichChar.scala b/src/library/scala/runtime/RichChar.scala index ba939d6633..918fe70f5c 100644 --- a/src/library/scala/runtime/RichChar.scala +++ b/src/library/scala/runtime/RichChar.scala @@ -10,7 +10,10 @@ package scala.runtime import java.lang.Character -final class RichChar(val self: Char) extends IntegralProxy[Char] { +final class RichChar(val self: Char) extends AnyVal with IntegralProxy[Char] { + protected def num = scala.math.Numeric.CharIsIntegral + protected def ord = scala.math.Ordering.Char + def asDigit: Int = Character.digit(self, Character.MAX_RADIX) def isControl: Boolean = Character.isISOControl(self) diff --git a/src/library/scala/runtime/RichDouble.scala b/src/library/scala/runtime/RichDouble.scala index 396323d1e8..19396a3d48 100644 --- a/src/library/scala/runtime/RichDouble.scala +++ b/src/library/scala/runtime/RichDouble.scala @@ -8,8 +8,10 @@ package scala.runtime -final class RichDouble(val self: Double) extends FractionalProxy[Double] { - protected val integralNum = Numeric.DoubleAsIfIntegral +final class RichDouble(val self: Double) extends AnyVal with FractionalProxy[Double] { + protected def num = scala.math.Numeric.DoubleIsFractional + protected def ord = scala.math.Ordering.Double + protected def integralNum = scala.math.Numeric.DoubleAsIfIntegral def round: Long = math.round(self) def ceil: Double = math.ceil(self) diff --git a/src/library/scala/runtime/RichFloat.scala b/src/library/scala/runtime/RichFloat.scala index 4fc9e8864a..9fbb3c19bb 100644 --- a/src/library/scala/runtime/RichFloat.scala +++ b/src/library/scala/runtime/RichFloat.scala @@ -8,8 +8,10 @@ package scala.runtime -final class RichFloat(val self: Float) extends FractionalProxy[Float] { - protected val integralNum = Numeric.FloatAsIfIntegral +final class RichFloat(val self: Float) extends AnyVal with FractionalProxy[Float] { + protected def num = scala.math.Numeric.FloatIsFractional + protected def ord = scala.math.Ordering.Float + protected def integralNum = scala.math.Numeric.FloatAsIfIntegral def round: Int = math.round(self) def ceil: Float = math.ceil(self).toFloat diff --git a/src/library/scala/runtime/RichInt.scala b/src/library/scala/runtime/RichInt.scala index d03968212f..619574264a 100644 --- a/src/library/scala/runtime/RichInt.scala +++ b/src/library/scala/runtime/RichInt.scala @@ -12,7 +12,9 @@ import scala.collection.immutable.Range // Note that this does not implement IntegralProxy[Int] so that it can return // the Int-specific Range class from until/to. -final class RichInt(val self: Int) extends ScalaNumberProxy[Int] with RangedProxy[Int] { +final class RichInt(val self: Int) extends AnyVal with ScalaNumberProxy[Int] with RangedProxy[Int] { + protected def num = scala.math.Numeric.IntIsIntegral + protected def ord = scala.math.Ordering.Int type ResultWithoutStep = Range /** diff --git a/src/library/scala/runtime/RichLong.scala b/src/library/scala/runtime/RichLong.scala index 5784934ffd..7c052851a9 100644 --- a/src/library/scala/runtime/RichLong.scala +++ b/src/library/scala/runtime/RichLong.scala @@ -8,7 +8,10 @@ package scala.runtime -final class RichLong(val self: Long) extends IntegralProxy[Long] { +final class RichLong(val self: Long) extends AnyVal with IntegralProxy[Long] { + protected def num = scala.math.Numeric.LongIsIntegral + protected def ord = scala.math.Ordering.Long + def toBinaryString: String = java.lang.Long.toBinaryString(self) def toHexString: String = java.lang.Long.toHexString(self) def toOctalString: String = java.lang.Long.toOctalString(self) diff --git a/src/library/scala/runtime/RichShort.scala b/src/library/scala/runtime/RichShort.scala index a174438c06..4dfa237b38 100644 --- a/src/library/scala/runtime/RichShort.scala +++ b/src/library/scala/runtime/RichShort.scala @@ -8,4 +8,7 @@ package scala.runtime -final class RichShort(val self: Short) extends ScalaWholeNumberProxy[Short] { } +final class RichShort(val self: Short) extends AnyVal with ScalaWholeNumberProxy[Short] { + protected def num = scala.math.Numeric.ShortIsIntegral + protected def ord = scala.math.Ordering.Short +} diff --git a/src/library/scala/runtime/ScalaNumberProxy.scala b/src/library/scala/runtime/ScalaNumberProxy.scala index d9b9a7843f..64df4611e3 100644 --- a/src/library/scala/runtime/ScalaNumberProxy.scala +++ b/src/library/scala/runtime/ScalaNumberProxy.scala @@ -20,9 +20,8 @@ import Proxy.Typed * @version 2.9 * @since 2.9 */ -abstract class ScalaNumberProxy[T: Numeric] extends ScalaNumericConversions with Typed[T] with OrderedProxy[T] { - private val num = implicitly[Numeric[T]] - protected val ord: Ordering[T] = num +trait ScalaNumberProxy[T] extends Any with ScalaNumericConversions with Typed[T] with OrderedProxy[T] { + protected implicit def num: Numeric[T] def underlying() = self.asInstanceOf[AnyRef] def doubleValue() = num.toDouble(self) @@ -35,11 +34,11 @@ abstract class ScalaNumberProxy[T: Numeric] extends ScalaNumericConversions with def abs = num.abs(self) def signum = num.signum(self) } -abstract class ScalaWholeNumberProxy[T: Numeric] extends ScalaNumberProxy[T] { +trait ScalaWholeNumberProxy[T] extends Any with ScalaNumberProxy[T] { def isWhole() = true } -abstract class IntegralProxy[T : Integral] extends ScalaWholeNumberProxy[T] with RangedProxy[T] { - private lazy val num = implicitly[Integral[T]] +trait IntegralProxy[T] extends Any with ScalaWholeNumberProxy[T] with RangedProxy[T] { + protected implicit def num: Integral[T] type ResultWithoutStep = NumericRange[T] def until(end: T): NumericRange.Exclusive[T] = NumericRange(self, end, num.one) @@ -47,17 +46,17 @@ abstract class IntegralProxy[T : Integral] extends ScalaWholeNumberProxy[T] with def to(end: T): NumericRange.Inclusive[T] = NumericRange.inclusive(self, end, num.one) def to(end: T, step: T): NumericRange.Inclusive[T] = NumericRange.inclusive(self, end, step) } -abstract class FractionalProxy[T : Fractional] extends ScalaNumberProxy[T] with RangedProxy[T] { - def isWhole() = false +trait FractionalProxy[T] extends Any with ScalaNumberProxy[T] with RangedProxy[T] { + protected implicit def num: Fractional[T] + protected implicit def integralNum: Integral[T] /** In order to supply predictable ranges, we require an Integral[T] which provides * us with discrete operations on the (otherwise fractional) T. See Numeric.DoubleAsIfIntegral * for an example. */ - protected implicit def integralNum: Integral[T] - private lazy val num = implicitly[Fractional[T]] type ResultWithoutStep = Range.Partial[T, NumericRange[T]] + def isWhole() = false def until(end: T): ResultWithoutStep = new Range.Partial(NumericRange(self, end, _)) def until(end: T, step: T): NumericRange.Exclusive[T] = NumericRange(self, end, step) def to(end: T): ResultWithoutStep = new Range.Partial(NumericRange.inclusive(self, end, _)) diff --git a/src/library/scala/runtime/StringAdd.scala b/src/library/scala/runtime/StringAdd.scala index a7e78ea9a3..4693b0bf44 100644 --- a/src/library/scala/runtime/StringAdd.scala +++ b/src/library/scala/runtime/StringAdd.scala @@ -9,14 +9,11 @@ package scala.runtime /** A wrapper class that adds string concatenation `+` to any value */ -final class StringAdd(val self: Any) { - +final class StringAdd(val self: Any) extends AnyVal { // 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 c120cbb14d..1f5feec9e1 100644 --- a/src/library/scala/runtime/StringFormat.scala +++ b/src/library/scala/runtime/StringFormat.scala @@ -10,8 +10,7 @@ package scala.runtime /** A wrapper class that adds a `formatted` operation to any value */ -final class StringFormat(val self: Any) { - +final class StringFormat(val self: Any) extends AnyVal { // 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 @@ -23,5 +22,4 @@ final class StringFormat(val self: Any) { * (@see java.lang.String.format). */ @inline def formatted(fmtstr: String): String = fmtstr format self - } diff --git a/src/library/scala/runtime/Tuple2Zipped.scala b/src/library/scala/runtime/Tuple2Zipped.scala index dce7eef08d..182fd77133 100644 --- a/src/library/scala/runtime/Tuple2Zipped.scala +++ b/src/library/scala/runtime/Tuple2Zipped.scala @@ -16,7 +16,7 @@ import language.{ higherKinds, implicitConversions } * by the requirement to resolve type constructors, for implicit search (which only * needs to find an implicit conversion to Traversable for our purposes.) */ -trait ZippedTraversable2[+El1, +El2] { +trait ZippedTraversable2[+El1, +El2] extends Any { def foreach[U](f: (El1, El2) => U): Unit } object ZippedTraversable2 { @@ -27,16 +27,15 @@ object ZippedTraversable2 { } } -class Tuple2Zipped[El1, Repr1, El2, Repr2]( - coll1: TraversableLike[El1, Repr1], - coll2: IterableLike[El2, Repr2] -) extends ZippedTraversable2[El1, El2] { +final class Tuple2Zipped[El1, Repr1, El2, Repr2](val colls: (TraversableLike[El1, Repr1], IterableLike[El2, Repr2])) extends AnyVal with ZippedTraversable2[El1, El2] { + // This would be better as "private def coll1 = colls._1" but + // SI-6215 precludes private methods in value classes. def map[B, To](f: (El1, El2) => B)(implicit cbf: CBF[Repr1, B, To]): To = { - val b = cbf(coll1.repr) - b.sizeHint(coll1) - val elems2 = coll2.iterator + val b = cbf(colls._1.repr) + b.sizeHint(colls._1) + val elems2 = colls._2.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext) b += f(el1, elems2.next) else @@ -47,10 +46,10 @@ class Tuple2Zipped[El1, Repr1, El2, Repr2]( } def flatMap[B, To](f: (El1, El2) => TraversableOnce[B])(implicit cbf: CBF[Repr1, B, To]): To = { - val b = cbf(coll1.repr) - val elems2 = coll2.iterator + val b = cbf(colls._1.repr) + val elems2 = colls._2.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext) b ++= f(el1, elems2.next) else @@ -61,11 +60,11 @@ class Tuple2Zipped[El1, Repr1, El2, Repr2]( } def filter[To1, To2](f: (El1, El2) => Boolean)(implicit cbf1: CBF[Repr1, El1, To1], cbf2: CBF[Repr2, El2, To2]): (To1, To2) = { - val b1 = cbf1(coll1.repr) - val b2 = cbf2(coll2.repr) - val elems2 = coll2.iterator + val b1 = cbf1(colls._1.repr) + val b2 = cbf2(colls._2.repr) + val elems2 = colls._2.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext) { val el2 = elems2.next if (f(el1, el2)) { @@ -80,9 +79,9 @@ class Tuple2Zipped[El1, Repr1, El2, Repr2]( } def exists(f: (El1, El2) => Boolean): Boolean = { - val elems2 = coll2.iterator + val elems2 = colls._2.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext) { if (f(el1, elems2.next)) return true @@ -96,9 +95,9 @@ class Tuple2Zipped[El1, Repr1, El2, Repr2]( !exists((x, y) => !f(x, y)) def foreach[U](f: (El1, El2) => U): Unit = { - val elems2 = coll2.iterator + val elems2 = colls._2.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext) f(el1, elems2.next) else @@ -108,7 +107,7 @@ class Tuple2Zipped[El1, Repr1, El2, Repr2]( } object Tuple2Zipped { - class Ops[T1, T2](x: (T1, T2)) { + final class Ops[T1, T2](val x: (T1, T2)) extends AnyVal { def invert[El1, CC1[X] <: TraversableOnce[X], El2, CC2[X] <: TraversableOnce[X], That] (implicit w1: T1 <:< CC1[El1], w2: T2 <:< CC2[El2], @@ -119,13 +118,13 @@ object Tuple2Zipped { val it2 = x._2.toIterator while (it1.hasNext && it2.hasNext) buf += ((it1.next, it2.next)) - + buf.result } def zipped[El1, Repr1, El2, Repr2] (implicit w1: T1 => TraversableLike[El1, Repr1], w2: T2 => IterableLike[El2, Repr2] - ): Tuple2Zipped[El1, Repr1, El2, Repr2] = new Tuple2Zipped(x._1, x._2) + ): Tuple2Zipped[El1, Repr1, El2, Repr2] = new Tuple2Zipped((x._1, x._2)) } } diff --git a/src/library/scala/runtime/Tuple3Zipped.scala b/src/library/scala/runtime/Tuple3Zipped.scala index f3ca08649d..f6aafe41fb 100644 --- a/src/library/scala/runtime/Tuple3Zipped.scala +++ b/src/library/scala/runtime/Tuple3Zipped.scala @@ -13,7 +13,7 @@ import scala.collection.generic.{ CanBuildFrom => CBF } import language.{ higherKinds, implicitConversions } /** See comment on ZippedTraversable2. */ -trait ZippedTraversable3[+El1, +El2, +El3] { +trait ZippedTraversable3[+El1, +El2, +El3] extends Any { def foreach[U](f: (El1, El2, El3) => U): Unit } object ZippedTraversable3 { @@ -24,17 +24,15 @@ object ZippedTraversable3 { } } -class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3]( - coll1: TraversableLike[El1, Repr1], - coll2: IterableLike[El2, Repr2], - coll3: IterableLike[El3, Repr3] -) extends ZippedTraversable3[El1, El2, El3] { +final class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3](val colls: (TraversableLike[El1, Repr1], IterableLike[El2, Repr2], IterableLike[El3, Repr3])) + extends AnyVal with ZippedTraversable3[El1, El2, El3] { + def map[B, To](f: (El1, El2, El3) => B)(implicit cbf: CBF[Repr1, B, To]): To = { - val b = cbf(coll1.repr) - val elems2 = coll2.iterator - val elems3 = coll3.iterator + val b = cbf(colls._1.repr) + val elems2 = colls._2.iterator + val elems3 = colls._3.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext && elems3.hasNext) b += f(el1, elems2.next, elems3.next) else @@ -44,11 +42,11 @@ class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3]( } def flatMap[B, To](f: (El1, El2, El3) => TraversableOnce[B])(implicit cbf: CBF[Repr1, B, To]): To = { - val b = cbf(coll1.repr) - val elems2 = coll2.iterator - val elems3 = coll3.iterator + val b = cbf(colls._1.repr) + val elems2 = colls._2.iterator + val elems3 = colls._3.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext && elems3.hasNext) b ++= f(el1, elems2.next, elems3.next) else @@ -61,14 +59,14 @@ class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3]( implicit cbf1: CBF[Repr1, El1, To1], cbf2: CBF[Repr2, El2, To2], cbf3: CBF[Repr3, El3, To3]): (To1, To2, To3) = { - val b1 = cbf1(coll1.repr) - val b2 = cbf2(coll2.repr) - val b3 = cbf3(coll3.repr) - val elems2 = coll2.iterator - val elems3 = coll3.iterator + val b1 = cbf1(colls._1.repr) + val b2 = cbf2(colls._2.repr) + val b3 = cbf3(colls._3.repr) + val elems2 = colls._2.iterator + val elems3 = colls._3.iterator def result = (b1.result, b2.result, b3.result) - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext && elems3.hasNext) { val el2 = elems2.next val el3 = elems3.next @@ -86,10 +84,10 @@ class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3]( } def exists(f: (El1, El2, El3) => Boolean): Boolean = { - val elems2 = coll2.iterator - val elems3 = coll3.iterator + val elems2 = colls._2.iterator + val elems3 = colls._3.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext && elems3.hasNext) { if (f(el1, elems2.next, elems3.next)) return true @@ -103,10 +101,10 @@ class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3]( !exists((x, y, z) => !f(x, y, z)) def foreach[U](f: (El1, El2, El3) => U): Unit = { - val elems2 = coll2.iterator - val elems3 = coll3.iterator + val elems2 = colls._2.iterator + val elems3 = colls._3.iterator - for (el1 <- coll1) { + for (el1 <- colls._1) { if (elems2.hasNext && elems3.hasNext) f(el1, elems2.next, elems3.next) else @@ -116,7 +114,7 @@ class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3]( } object Tuple3Zipped { - class Ops[T1, T2, T3](x: (T1, T2, T3)) { + final class Ops[T1, T2, T3](val x: (T1, T2, T3)) extends AnyVal { def invert[El1, CC1[X] <: TraversableOnce[X], El2, CC2[X] <: TraversableOnce[X], El3, CC3[X] <: TraversableOnce[X], That] (implicit w1: T1 <:< CC1[El1], w2: T2 <:< CC2[El2], @@ -129,14 +127,14 @@ object Tuple3Zipped { val it3 = x._3.toIterator while (it1.hasNext && it2.hasNext && it3.hasNext) buf += ((it1.next, it2.next, it3.next)) - + buf.result } - + def zipped[El1, Repr1, El2, Repr2, El3, Repr3] (implicit w1: T1 => TraversableLike[El1, Repr1], w2: T2 => IterableLike[El2, Repr2], w3: T3 => IterableLike[El3, Repr3] - ): Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3] = new Tuple3Zipped(x._1, x._2, x._3) + ): Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3] = new Tuple3Zipped((x._1, x._2, x._3)) } } diff --git a/test/files/neg/t900.check b/test/files/neg/t900.check index 4611ceba8c..ff5304a135 100644 --- a/test/files/neg/t900.check +++ b/test/files/neg/t900.check @@ -1,10 +1,6 @@ t900.scala:4: error: type mismatch; found : Foo.this.x.type (with underlying type Foo.this.bar) required: AnyRef -Note that implicit conversions are not applicable because they are ambiguous: - both method any2stringfmt in object Predef of type (x: Any)scala.runtime.StringFormat - and method any2stringadd in object Predef of type (x: Any)scala.runtime.StringAdd - are possible conversion functions from Foo.this.x.type to AnyRef def break(): x.type ^ one error found diff --git a/test/files/neg/unit2anyref.check b/test/files/neg/unit2anyref.check index 10fe1861f5..6d11461700 100644 --- a/test/files/neg/unit2anyref.check +++ b/test/files/neg/unit2anyref.check @@ -1,8 +1,6 @@ unit2anyref.scala:2: error: type mismatch; found : Unit required: AnyRef -Note: Unit is not implicitly converted to AnyRef. You can safely -pattern match `x: AnyRef` or cast `x.asInstanceOf[AnyRef]` to do so. val x: AnyRef = () // this should not succeed. ^ one error found diff --git a/test/files/run/richWrapperEquals.scala b/test/files/run/richWrapperEquals.scala index 44beb133b3..4a43617cde 100644 --- a/test/files/run/richWrapperEquals.scala +++ b/test/files/run/richWrapperEquals.scala @@ -1,10 +1,6 @@ object Test { def main(args: Array[String]): Unit = { - assert(intWrapper(5) == 5) - assert(5 == intWrapper(5)) assert(5 == (5: java.lang.Integer)) assert((5: java.lang.Integer) == 5) - assert((5: java.lang.Integer) == intWrapper(5)) - assert(intWrapper(5) == (5: java.lang.Integer)) } } diff --git a/test/files/run/t5356.check b/test/files/run/t5356.check index 21c4aef07b..7522e7ea74 100644 --- a/test/files/run/t5356.check +++ b/test/files/run/t5356.check @@ -1,6 +1,6 @@ -1 scala.runtime.RichInt -1 scala.runtime.RichInt +1 java.lang.Integer +1 java.lang.Integer 1 scala.math.BigInt -1 scala.runtime.RichDouble -1 scala.runtime.RichFloat +1 java.lang.Double +1 java.lang.Float 1 diff --git a/test/files/run/t5356.scala b/test/files/run/t5356.scala index f7696c6088..ec17e036ad 100644 --- a/test/files/run/t5356.scala +++ b/test/files/run/t5356.scala @@ -1,12 +1,12 @@ object Test { - def f(x: { def toInt: Int }) = println(x.toInt + " " + x.getClass.getName) - + def f(x: Any { def toInt: Int }) = println(x.toInt + " " + x.getClass.getName) + def main(args: Array[String]): Unit = { f(1) f(1.toInt) f(BigInt(1)) f(1d) f(1f) - println((1: { def toInt: Int }).toInt) + println((1: (Any { def toInt: Int })).toInt) } } |