Skip to content

Commit 839c37e

Browse files
committed
Drop StrictFactory and capture check library-js version of Array instead
Without the capture-checked Array, Factory[Array] cannot be proven strict.
1 parent 98e7b80 commit 839c37e

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

library-js/src/scala/Array.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
package scala
1414

15+
import language.experimental.captureChecking
16+
1517
//import scala.collection.generic._
1618
import scala.collection.{Factory, immutable, mutable}
1719
import mutable.ArrayBuilder
@@ -61,7 +63,7 @@ object Array {
6163
implicit def toFactory[A : ClassTag](dummy: Array.type): Factory[A, Array[A]] = new ArrayFactory(dummy)
6264
@SerialVersionUID(3L)
6365
private class ArrayFactory[A : ClassTag](dummy: Array.type) extends Factory[A, Array[A]] with Serializable {
64-
def fromSpecific(it: IterableOnce[A]): Array[A] = Array.from[A](it)
66+
def fromSpecific(it: IterableOnce[A]^): Array[A] = Array.from[A](it)
6567
def newBuilder: mutable.Builder[A, Array[A]] = Array.newBuilder[A]
6668
}
6769

@@ -70,7 +72,7 @@ object Array {
7072
*/
7173
def newBuilder[T](implicit t: ClassTag[T]): ArrayBuilder[T] = ArrayBuilder.make[T](using t)
7274

73-
def from[A : ClassTag](it: IterableOnce[A]): Array[A] = {
75+
def from[A: ClassTag](it: IterableOnce[A]^): Array[A] = {
7476
val n = it.knownSize
7577
if (n > -1) {
7678
val elements = new Array[A](n)
@@ -656,7 +658,7 @@ object Array {
656658
* @define collectExample
657659
* @define undefinedorder
658660
*/
659-
final class Array[T](_length: Int) extends java.io.Serializable with java.lang.Cloneable {
661+
final class Array[T](_length: Int) extends java.io.Serializable with java.lang.Cloneable { self =>
660662

661663
/** The length of the array */
662664
def length: Int = throw new Error()

library/src/scala/collection/Factory.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,11 @@ trait Factory[-A, +C] extends Any { self =>
4646
def newBuilder: Builder[A, C]
4747
}
4848

49-
/** A strict version of [[Factory]], where the returned collection from [[fromSpecific]] do not capture its input. */
50-
trait StrictFactory[-A, +C] extends Factory[A, C] {
51-
override def fromSpecific(it: IterableOnce[A]^): C
52-
}
53-
5449
object Factory {
5550

56-
implicit val stringFactory: StrictFactory[Char, String] = new StringFactory
51+
implicit val stringFactory: Factory[Char, String] = new StringFactory
5752
@SerialVersionUID(3L)
58-
private class StringFactory extends StrictFactory[Char, String] with Serializable {
53+
private class StringFactory extends Factory[Char, String] with Serializable {
5954
def fromSpecific(it: IterableOnce[Char]^): String = {
6055
val b = new mutable.StringBuilder(scala.math.max(0, it.knownSize))
6156
b ++= it
@@ -64,9 +59,9 @@ object Factory {
6459
def newBuilder: Builder[Char, String] = new mutable.StringBuilder()
6560
}
6661

67-
implicit def arrayFactory[A: ClassTag]: StrictFactory[A, Array[A]] = new ArrayFactory[A]
62+
implicit def arrayFactory[A: ClassTag]: Factory[A, Array[A]] = new ArrayFactory[A]
6863
@SerialVersionUID(3L)
69-
private class ArrayFactory[A: ClassTag] extends StrictFactory[A, Array[A]] with Serializable {
64+
private class ArrayFactory[A: ClassTag] extends Factory[A, Array[A]] with Serializable {
7065
def fromSpecific(it: IterableOnce[A]^): Array[A] = {
7166
val b = newBuilder
7267
b.sizeHint(it, delta = 0)

0 commit comments

Comments
 (0)