Skip to content

Commit 5c6e542

Browse files
committed
Move sources from tests/pos-special/stdlib to scala2-library-cc
Also reduce diff with the original Scala 2 library sources.
1 parent d0c4817 commit 5c6e542

File tree

151 files changed

+119
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+119
-264
lines changed

compiler/test/dotty/Properties.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ object Properties {
8787

8888
/** If we are using the scala-library TASTy jar */
8989
def usingScalaLibraryTasty: Boolean = scalaLibraryTasty.isDefined
90+
/** If we are using the scala-library TASTy jar */
91+
92+
def usingScalaLibraryCCTasty: Boolean = scalaLibraryTasty.exists(_.contains("scala2-library-cc-tasty"))
9093

9194
/** scala-asm jar */
9295
def scalaAsm: String = sys.props("dotty.tests.classes.scalaAsm")

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class CompilationTests {
4545
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init", "-Ylegacy-lazy-vals", "-Ycheck-constraint-deps"), FileFilter.include(TestSources.posLazyValsAllowlist)),
4646
compileDir("tests/pos-special/java-param-names", defaultOptions.withJavacOnlyOptions("-parameters")),
4747
) ::: (
48-
// FIXME: This fails due to a bug involving self types and capture checking
49-
if Properties.usingScalaLibraryTasty then Nil
50-
else List(compileDir("tests/pos-special/stdlib", allowDeepSubtypes))
48+
// TODO create a folder for capture checking tests with the stdlib, or use tests/pos-custom-args/captures under this mode?
49+
if Properties.usingScalaLibraryCCTasty then List(compileDir("tests/pos-special/stdlib", allowDeepSubtypes))
50+
else Nil
5151
)
5252

5353
if scala.util.Properties.isJavaAtLeast("16") then

tests/pos-special/stdlib/collection/ArrayOps.scala renamed to scala2-library-cc/src/scala/collection/ArrayOps.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ object ArrayOps {
113113
b.result()
114114
}
115115

116-
def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], m: ClassTag[B]): Array[B] =
116+
def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], m: ClassTag[B]): Array[B] =
117117
flatMap[B](x => asIterable(f(x)))
118118

119119
/** Creates a new non-strict filter which combines this filter with the given predicate. */
@@ -505,7 +505,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
505505
*
506506
* @return a pair of arrays: the first one made of those values returned by `f` that were wrapped in [[scala.util.Left]],
507507
* and the second one made of those wrapped in [[scala.util.Right]]. */
508-
def partitionMap[A1: ClassTag, A2: ClassTag](f: A => Either[A1, A2]): (Array[A1], Array[A2]) = {
508+
def partitionMap[A1: ClassTag, A2: ClassTag](f: A => Either[A1, A2]): (Array[A1], Array[A2]) = {
509509
val res1 = ArrayBuilder.make[A1]
510510
val res2 = ArrayBuilder.make[A2]
511511
var i = 0
@@ -816,7 +816,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
816816
* }}}
817817
*
818818
*/
819-
def scanLeft[B : ClassTag](z: B)(op: (B, A) => B): Array[B] = {
819+
def scanLeft[ B : ClassTag ](z: B)(op: (B, A) => B): Array[B] = {
820820
var v = z
821821
var i = 0
822822
val res = new Array[B](xs.length + 1)
@@ -855,7 +855,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
855855
* }}}
856856
*
857857
*/
858-
def scanRight[B : ClassTag](z: B)(op: (A, B) => B): Array[B] = {
858+
def scanRight[ B : ClassTag ](z: B)(op: (A, B) => B): Array[B] = {
859859
var v = z
860860
var i = xs.length - 1
861861
val res = new Array[B](xs.length + 1)
@@ -973,7 +973,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
973973
b.result()
974974
}
975975

976-
def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], m: ClassTag[B]): Array[B] =
976+
def flatMap[BS, B](f: A => BS)(implicit asIterable: BS => Iterable[B], m: ClassTag[B]): Array[B] =
977977
flatMap[B](x => asIterable(f(x)))
978978

979979
/** Flattens a two-dimensional array by concatenating all its rows
@@ -1095,7 +1095,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
10951095
* If this array is shorter than `that`, `thisElem` values are used to pad the result.
10961096
* If `that` is shorter than this array, `thatElem` values are used to pad the result.
10971097
*/
1098-
def zipAll[A1 >: A, B](that: Iterable[B], thisElem: A1, thatElem: B): Array[(A1, B)] = {
1098+
def zipAll[A1 >: A, B](that: Iterable[B], thisElem: A1, thatElem: B): Array[(A1, B)] = {
10991099
val b = new ArrayBuilder.ofRef[(A1, B)]()
11001100
val k = that.knownSize
11011101
b.sizeHint(max(k, xs.length))
@@ -1244,7 +1244,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
12441244
* @return a pair of Arrays, containing, respectively, the first and second half
12451245
* of each element pair of this Array.
12461246
*/
1247-
def unzip[A1, A2](implicit asPair: A => (A1, A2), ct1: ClassTag[A1], ct2: ClassTag[A2]): (Array[A1], Array[A2]) = {
1247+
def unzip[A1, A2](implicit asPair: A => (A1, A2), ct1: ClassTag[A1], ct2: ClassTag[A2]): (Array[A1], Array[A2]) = {
12481248
val a1 = new Array[A1](xs.length)
12491249
val a2 = new Array[A2](xs.length)
12501250
var i = 0
@@ -1273,7 +1273,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
12731273
* @return a triple of Arrays, containing, respectively, the first, second, and third
12741274
* elements from each element triple of this Array.
12751275
*/
1276-
def unzip3[A1, A2, A3](implicit asTriple: A => (A1, A2, A3), ct1: ClassTag[A1], ct2: ClassTag[A2],
1276+
def unzip3[A1, A2, A3](implicit asTriple: A => (A1, A2, A3), ct1: ClassTag[A1], ct2: ClassTag[A2],
12771277
ct3: ClassTag[A3]): (Array[A1], Array[A2], Array[A3]) = {
12781278
val a1 = new Array[A1](xs.length)
12791279
val a2 = new Array[A2](xs.length)
@@ -1418,7 +1418,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
14181418
* @tparam K the type of keys returned by the discriminator function
14191419
* @tparam B the type of values returned by the transformation function
14201420
*/
1421-
def groupMap[K, B : ClassTag](key: A => K)(f: A => B): immutable.Map[K, Array[B]] = {
1421+
def groupMap[K, B : ClassTag](key: A => K)(f: A => B): immutable.Map[K, Array[B]] = {
14221422
val m = mutable.Map.empty[K, ArrayBuilder[B]]
14231423
val len = xs.length
14241424
var i = 0
@@ -1479,7 +1479,8 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
14791479
/** Create a copy of this array with the specified element type. */
14801480
def toArray[B >: A: ClassTag]: Array[B] = {
14811481
val destination = new Array[B](xs.length)
1482-
copyToArray(destination, 0)
1482+
@annotation.unused val copied = copyToArray(destination, 0)
1483+
//assert(copied == xs.length)
14831484
destination
14841485
}
14851486

tests/pos-special/stdlib/collection/BuildFrom.scala renamed to scala2-library-cc/src/scala/collection/BuildFrom.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ object BuildFrom extends BuildFromLowPriority1 {
8787
def newBuilder(from: Array[_]): Builder[A, Array[A]] = Factory.arrayFactory[A].newBuilder
8888
}
8989

90-
implicit def buildFromView[A, B]: BuildFrom[View[A], B, View[B]] =
90+
implicit def buildFromView[A, B]: BuildFrom[View[A], B, View[B]] =
9191
new BuildFrom[View[A], B, View[B]] {
9292
def fromSpecific(from: View[A])(it: IterableOnce[B]^): View[B] = View.from(it).unsafeAssumePure
9393
def newBuilder(from: View[A]): Builder[B, View[B]] = View.newBuilder

tests/pos-special/stdlib/collection/IndexedSeq.scala renamed to scala2-library-cc/src/scala/collection/IndexedSeq.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,25 @@ trait IndexedSeqOps[+A, +CC[_], +C] extends Any with IndexedSeqViewOps[A, CC, C]
9494

9595
override def slice(from: Int, until: Int): C = fromSpecific(new IndexedSeqView.Slice(this, from, until))
9696

97-
override def head: A = apply(0)
97+
override def head: A =
98+
if (!isEmpty) apply(0)
99+
else throw new NoSuchElementException(s"head of empty ${
100+
self match {
101+
case self: IndexedSeq[_] => self.collectionClassName
102+
case _ => toString
103+
}
104+
}")
98105

99106
override def headOption: Option[A] = if (isEmpty) None else Some(head)
100107

101-
override def last: A = apply(length - 1)
108+
override def last: A =
109+
if (!isEmpty) apply(length - 1)
110+
else throw new NoSuchElementException(s"last of empty ${
111+
self match {
112+
case self: IndexedSeq[_] => self.collectionClassName
113+
case _ => toString
114+
}
115+
}")
102116

103117
// We already inherit an efficient `lastOption = if (isEmpty) None else Some(last)`
104118

0 commit comments

Comments
 (0)