Skip to content

Commit 6f04d05

Browse files
julienrfashawley
authored andcommitted
Use immutable.Seq and Iterable
Preparation for the new collections library. Cherry-picked from work on trying to: Add support for Scala 2.13-M4
1 parent 2545d8d commit 6f04d05

File tree

13 files changed

+34
-30
lines changed

13 files changed

+34
-30
lines changed

doc/UserGuide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,15 +873,15 @@ object CounterSpecification extends Commands {
873873
* (a singleton [[Sut]]), implement this method the following way:
874874
*
875875
* {{{
876-
* def canCreateNewSut(newState: State, initSuts: Traversable[State]
877-
* runningSuts: Traversable[Sut]
876+
* def canCreateNewSut(newState: State, initSuts: Iterable[State]
877+
* runningSuts: Iterable[Sut]
878878
* ) = {
879879
* initSuts.isEmpty && runningSuts.isEmpty
880880
* }
881881
* }}}
882882
*/
883-
def canCreateNewSut(newState: State, initSuts: Traversable[State],
884-
runningSuts: Traversable[Sut]): Boolean = true
883+
def canCreateNewSut(newState: State, initSuts: Iterable[State],
884+
runningSuts: Iterable[Sut]): Boolean = true
885885

886886
/** The precondition for the initial state, when no commands yet have
887887
* run. This is used by ScalaCheck when command sequences are shrinked

jvm/src/test/scala/org/scalacheck/GenSpecification.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Arbitrary._
1717
import Shrink._
1818
import java.util.Date
1919
import scala.util.{Try, Success, Failure}
20+
import scala.collection.immutable.Seq
2021

2122
object GenSpecification extends Properties("Gen") {
2223

jvm/src/test/scala/org/scalacheck/commands/CommandsSpecification.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ object CommandsSpecification extends Properties("Commands") {
3030

3131
override def shrinkState: Shrink[Int] = implicitly
3232

33-
def canCreateNewSut(newState: State, initSuts: Traversable[State],
34-
runningSuts: Traversable[Sut]) = true
33+
def canCreateNewSut(newState: State, initSuts: Iterable[State],
34+
runningSuts: Iterable[Sut]) = true
3535

3636
def newSut(state: State): Sut = Counter(state)
3737

src/main/scala/org/scalacheck/Arbitrary.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ private[scalacheck] sealed trait ArbitraryLowPriority {
360360
* (such as lists, arrays, streams, etc). The maximum size of the container
361361
* depends on the size generation parameter. */
362362
implicit def arbContainer[C[_],T](implicit
363-
a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Traversable[T]
363+
a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Iterable[T]
364364
): Arbitrary[C[T]] = Arbitrary(buildableOf[C[T],T](arbitrary[T]))
365365

366366
/** Arbitrary instance of any [[org.scalacheck.util.Buildable]] container
367367
* (such as maps). The maximum size of the container depends on the size
368368
* generation parameter. */
369369
implicit def arbContainer2[C[_,_],T,U](implicit
370-
a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Traversable[(T,U)]
370+
a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Iterable[(T,U)]
371371
): Arbitrary[C[T,U]] = Arbitrary(buildableOf[C[T,U],(T,U)](arbitrary[(T,U)]))
372372

373373
implicit def arbEnum[A <: java.lang.Enum[A]](implicit A: reflect.ClassTag[A]): Arbitrary[A] = {

src/main/scala/org/scalacheck/Cogen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ object Cogen extends CogenArities with CogenLowPriority {
114114
Cogen[String].contramap(_.name)
115115

116116
implicit def cogenList[A: Cogen]: Cogen[List[A]] =
117-
Cogen.it(_.iterator)
117+
Cogen.it(_.iterator())
118118

119119
implicit def cogenVector[A: Cogen]: Cogen[Vector[A]] =
120120
Cogen.it(_.iterator)

src/main/scala/org/scalacheck/Gen.scala

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import util.Buildable
1717
import util.SerializableCanBuildFroms._
1818

1919
import scala.annotation.tailrec
20+
import scala.collection.immutable.Seq
2021
import scala.collection.immutable.TreeMap
2122
import scala.collection.mutable.ArrayBuffer
2223
import scala.concurrent.duration.{Duration, FiniteDuration}
@@ -449,7 +450,7 @@ object Gen extends GenArities{
449450

450451
/** Sequences generators. If any of the given generators fails, the
451452
* resulting generator will also fail. */
452-
def sequence[C,T](gs: Traversable[Gen[T]])(implicit b: Buildable[T,C]): Gen[C] = {
453+
def sequence[C,T](gs: Iterable[Gen[T]])(implicit b: Buildable[T,C]): Gen[C] = {
453454
val g = gen { (p, seed) =>
454455
gs.foldLeft(r(Some(Vector.empty[T]), seed)) {
455456
case (rs,g) =>
@@ -576,55 +577,55 @@ object Gen extends GenArities{
576577

577578
//// List Generators ////
578579

579-
/** Generates a container of any Traversable type for which there exists an
580+
/** Generates a container of any Iterable type for which there exists an
580581
* implicit [[org.scalacheck.util.Buildable]] instance. The elements in the
581582
* container will be generated by the given generator. The size of the
582583
* generated container is limited by `n`. Depending on what kind of container
583584
* that is generated, the resulting container may contain fewer elements than
584585
* `n`, but not more. If the given generator fails generating a value, the
585586
* complete container generator will also fail. */
586587
def buildableOfN[C,T](n: Int, g: Gen[T])(implicit
587-
evb: Buildable[T,C], evt: C => Traversable[T]
588+
evb: Buildable[T,C], evt: C => Iterable[T]
588589
): Gen[C] =
589-
sequence[C,T](Traversable.fill(n)(g)) suchThat { c =>
590+
sequence[C,T](Iterable.fill(n)(g)) suchThat { c =>
590591
// TODO: Can we guarantee c.size == n (See issue #89)?
591592
c.forall(g.sieveCopy)
592593
}
593594

594-
/** Generates a container of any Traversable type for which there exists an
595+
/** Generates a container of any Iterable type for which there exists an
595596
* implicit [[org.scalacheck.util.Buildable]] instance. The elements in the
596597
* container will be generated by the given generator. The size of the
597598
* container is bounded by the size parameter used when generating values. */
598599
def buildableOf[C,T](g: Gen[T])(implicit
599-
evb: Buildable[T,C], evt: C => Traversable[T]
600+
evb: Buildable[T,C], evt: C => Iterable[T]
600601
): Gen[C] =
601602
sized(s => choose(0, s max 0).flatMap(buildableOfN[C,T](_,g))) suchThat { c =>
602603
if (c == null) g.sieveCopy(null) else c.forall(g.sieveCopy)
603604
}
604605

605-
/** Generates a non-empty container of any Traversable type for which there
606+
/** Generates a non-empty container of any Iterable type for which there
606607
* exists an implicit [[org.scalacheck.util.Buildable]] instance. The
607608
* elements in the container will be generated by the given generator. The
608609
* size of the container is bounded by the size parameter used when
609610
* generating values. */
610611
def nonEmptyBuildableOf[C,T](g: Gen[T])(implicit
611-
evb: Buildable[T,C], evt: C => Traversable[T]
612+
evb: Buildable[T,C], evt: C => Iterable[T]
612613
): Gen[C] =
613614
sized(s => choose(1, s max 1).flatMap(buildableOfN[C,T](_,g))) suchThat(_.size > 0)
614615

615616
/** A convenience method for calling `buildableOfN[C[T],T](n,g)`. */
616617
def containerOfN[C[_],T](n: Int, g: Gen[T])(implicit
617-
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
618+
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
618619
): Gen[C[T]] = buildableOfN[C[T],T](n,g)
619620

620621
/** A convenience method for calling `buildableOf[C[T],T](g)`. */
621622
def containerOf[C[_],T](g: Gen[T])(implicit
622-
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
623+
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
623624
): Gen[C[T]] = buildableOf[C[T],T](g)
624625

625626
/** A convenience method for calling `nonEmptyBuildableOf[C[T],T](g)`. */
626627
def nonEmptyContainerOf[C[_],T](g: Gen[T])(implicit
627-
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
628+
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
628629
): Gen[C[T]] = nonEmptyBuildableOf[C[T],T](g)
629630

630631
/** Generates a list of random length. The maximum length depends on the

src/main/scala/org/scalacheck/Properties.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Properties(val name: String) {
4141

4242
/** Returns all properties of this collection in a list of name/property
4343
* pairs. */
44-
def properties: Seq[(String,Prop)] = props
44+
def properties: collection.Seq[(String,Prop)] = props
4545

4646
/** Convenience method that checks the properties with the given parameters
4747
* (or default parameters, if not specified)

src/main/scala/org/scalacheck/ScalaCheckFramework.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private abstract class ScalaCheckRunner extends Runner {
5151
abstract class BaseTask(override val taskDef: TaskDef) extends Task {
5252
val tags: Array[String] = Array()
5353

54-
val props: Seq[(String,Prop)] = {
54+
val props: collection.Seq[(String,Prop)] = {
5555
val fp = taskDef.fingerprint.asInstanceOf[SubclassFingerprint]
5656
val obj = if (fp.isModule) Platform.loadModule(taskDef.fullyQualifiedName,loader)
5757
else Platform.newInstance(taskDef.fullyQualifiedName, loader, Seq())(Seq())

src/main/scala/org/scalacheck/Shrink.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object Shrink extends ShrinkLowPriority {
4949
cons(x, s.shrink(x))
5050

5151
/** Shrink instance of container */
52-
implicit def shrinkContainer[C[_],T](implicit v: C[T] => Traversable[T], s: Shrink[T],
52+
implicit def shrinkContainer[C[_],T](implicit v: C[T] => Iterable[T], s: Shrink[T],
5353
b: Buildable[T,C[T]]
5454
): Shrink[C[T]] = Shrink { xs: C[T] =>
5555
val ys = v(xs)
@@ -58,7 +58,7 @@ object Shrink extends ShrinkLowPriority {
5858
}
5959

6060
/** Shrink instance of container2 */
61-
implicit def shrinkContainer2[C[_,_],T,U](implicit v: C[T,U] => Traversable[(T,U)], s: Shrink[(T,U)],
61+
implicit def shrinkContainer2[C[_,_],T,U](implicit v: C[T,U] => Iterable[(T,U)], s: Shrink[(T,U)],
6262
b: Buildable[(T,U),C[T,U]]
6363
): Shrink[C[T,U]] = Shrink { xs: C[T,U] =>
6464
val ys = v(xs)

src/main/scala/org/scalacheck/Test.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ package org.scalacheck
1111

1212
import Prop.Arg
1313

14+
import scala.collection.immutable.Seq
15+
1416
object Test {
1517

1618
import util.{FreqMap, CmdLineParser, ConsoleReporter}

0 commit comments

Comments
 (0)