diff options
-rw-r--r-- | src/library/scala/collection/Iterable.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/Iterator.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/Map.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/Seq.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/Set.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/Traversable.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/immutable/Map.scala | 6 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/Buffer.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/Iterable.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/Map.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/Seq.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/mutable/Set.scala | 2 | ||||
-rw-r--r-- | test/files/pos/t6948.scala | 10 | ||||
-rw-r--r-- | test/files/run/inferred-type-constructors.check | 56 | ||||
-rw-r--r-- | test/files/run/inferred-type-constructors.scala | 125 |
15 files changed, 205 insertions, 14 deletions
diff --git a/src/library/scala/collection/Iterable.scala b/src/library/scala/collection/Iterable.scala index 973efc447e..a5ab8efd5c 100644 --- a/src/library/scala/collection/Iterable.scala +++ b/src/library/scala/collection/Iterable.scala @@ -51,4 +51,4 @@ object Iterable extends TraversableFactory[Iterable] { } /** Explicit instantiation of the `Iterable` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractIterable[+A] extends AbstractTraversable[A] with Iterable[A] +abstract class AbstractIterable[+A] extends AbstractTraversable[A] with Iterable[A] diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 72a23a0dd0..01a0aa3b51 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -1171,4 +1171,4 @@ trait Iterator[+A] extends TraversableOnce[A] { } /** Explicit instantiation of the `Iterator` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractIterator[+A] extends Iterator[A] +abstract class AbstractIterator[+A] extends Iterator[A] diff --git a/src/library/scala/collection/Map.scala b/src/library/scala/collection/Map.scala index 761b65723c..1e40fd8c24 100644 --- a/src/library/scala/collection/Map.scala +++ b/src/library/scala/collection/Map.scala @@ -56,4 +56,4 @@ object Map extends MapFactory[Map] { } /** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractMap[A, +B] extends AbstractIterable[(A, B)] with Map[A, B] +abstract class AbstractMap[A, +B] extends AbstractIterable[(A, B)] with Map[A, B] diff --git a/src/library/scala/collection/Seq.scala b/src/library/scala/collection/Seq.scala index b21acdd9b7..2f4b3e5f8a 100644 --- a/src/library/scala/collection/Seq.scala +++ b/src/library/scala/collection/Seq.scala @@ -38,4 +38,4 @@ object Seq extends SeqFactory[Seq] { } /** Explicit instantiation of the `Seq` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractSeq[+A] extends AbstractIterable[A] with Seq[A] +abstract class AbstractSeq[+A] extends AbstractIterable[A] with Seq[A] diff --git a/src/library/scala/collection/Set.scala b/src/library/scala/collection/Set.scala index 46d5dfa056..f74c26571a 100644 --- a/src/library/scala/collection/Set.scala +++ b/src/library/scala/collection/Set.scala @@ -44,4 +44,4 @@ object Set extends SetFactory[Set] { } /** Explicit instantiation of the `Set` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A] +abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A] diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala index 61d9a42f04..b53724c568 100644 --- a/src/library/scala/collection/Traversable.scala +++ b/src/library/scala/collection/Traversable.scala @@ -101,4 +101,4 @@ object Traversable extends TraversableFactory[Traversable] { self => } /** Explicit instantiation of the `Traversable` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractTraversable[+A] extends Traversable[A] +abstract class AbstractTraversable[+A] extends Traversable[A] diff --git a/src/library/scala/collection/immutable/Map.scala b/src/library/scala/collection/immutable/Map.scala index 8933c7cf77..5178d5a862 100644 --- a/src/library/scala/collection/immutable/Map.scala +++ b/src/library/scala/collection/immutable/Map.scala @@ -32,9 +32,9 @@ trait Map[A, +B] extends Iterable[(A, B)] with MapLike[A, B, Map[A, B]] { self => override def empty: Map[A, B] = Map.empty - + /** Returns this $coll as an immutable map. - * + * * A new map will not be built; lazy collections will stay lazy. */ @deprecatedOverriding("Immutable maps should do nothing on toMap except return themselves cast as a map.", "2.11.0") @@ -191,4 +191,4 @@ object Map extends ImmutableMapFactory[Map] { } /** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractMap[A, +B] extends scala.collection.AbstractMap[A, B] with Map[A, B] +abstract class AbstractMap[A, +B] extends scala.collection.AbstractMap[A, B] with Map[A, B] diff --git a/src/library/scala/collection/mutable/Buffer.scala b/src/library/scala/collection/mutable/Buffer.scala index d2e33badbe..7ec7b06333 100644 --- a/src/library/scala/collection/mutable/Buffer.scala +++ b/src/library/scala/collection/mutable/Buffer.scala @@ -46,4 +46,4 @@ object Buffer extends SeqFactory[Buffer] { } /** Explicit instantiation of the `Buffer` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractBuffer[A] extends AbstractSeq[A] with Buffer[A] +abstract class AbstractBuffer[A] extends AbstractSeq[A] with Buffer[A] diff --git a/src/library/scala/collection/mutable/Iterable.scala b/src/library/scala/collection/mutable/Iterable.scala index f7a794e357..92313c9ccd 100644 --- a/src/library/scala/collection/mutable/Iterable.scala +++ b/src/library/scala/collection/mutable/Iterable.scala @@ -38,4 +38,4 @@ object Iterable extends TraversableFactory[Iterable] { } /** Explicit instantiation of the `Iterable` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractIterable[A] extends scala.collection.AbstractIterable[A] with Iterable[A] +abstract class AbstractIterable[A] extends scala.collection.AbstractIterable[A] with Iterable[A] diff --git a/src/library/scala/collection/mutable/Map.scala b/src/library/scala/collection/mutable/Map.scala index 01f6f725ab..fe29ce4221 100644 --- a/src/library/scala/collection/mutable/Map.scala +++ b/src/library/scala/collection/mutable/Map.scala @@ -89,4 +89,4 @@ object Map extends MutableMapFactory[Map] { } /** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractMap[A, B] extends scala.collection.AbstractMap[A, B] with Map[A, B] +abstract class AbstractMap[A, B] extends scala.collection.AbstractMap[A, B] with Map[A, B] diff --git a/src/library/scala/collection/mutable/Seq.scala b/src/library/scala/collection/mutable/Seq.scala index 11fbdd13f3..eafde70a2d 100644 --- a/src/library/scala/collection/mutable/Seq.scala +++ b/src/library/scala/collection/mutable/Seq.scala @@ -45,4 +45,4 @@ object Seq extends SeqFactory[Seq] { } /** Explicit instantiation of the `Seq` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractSeq[A] extends scala.collection.AbstractSeq[A] with Seq[A] +abstract class AbstractSeq[A] extends scala.collection.AbstractSeq[A] with Seq[A] diff --git a/src/library/scala/collection/mutable/Set.scala b/src/library/scala/collection/mutable/Set.scala index 4439880976..97574718e8 100644 --- a/src/library/scala/collection/mutable/Set.scala +++ b/src/library/scala/collection/mutable/Set.scala @@ -43,4 +43,4 @@ object Set extends MutableSetFactory[Set] { } /** Explicit instantiation of the `Set` trait to reduce class file size in subclasses. */ -private[scala] abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A] +abstract class AbstractSet[A] extends AbstractIterable[A] with Set[A] diff --git a/test/files/pos/t6948.scala b/test/files/pos/t6948.scala new file mode 100644 index 0000000000..12a1d7eaf2 --- /dev/null +++ b/test/files/pos/t6948.scala @@ -0,0 +1,10 @@ +object t6948 { + val rand = new scala.util.Random() + def a1 = rand.shuffle(0 to 5) + // Tis not to be + // def a2 = rand.shuffle(0 until 5) + def a3 = rand.shuffle(Vector(1, 2, 3)) + def a4 = rand.shuffle(scala.collection.Seq(1, 2, 3)) + def a5 = rand.shuffle(scala.collection.immutable.Seq(1, 2, 3)) + def a6 = rand.shuffle(scala.collection.mutable.Seq(1, 2, 3)) +} diff --git a/test/files/run/inferred-type-constructors.check b/test/files/run/inferred-type-constructors.check new file mode 100644 index 0000000000..5992ef02ad --- /dev/null +++ b/test/files/run/inferred-type-constructors.check @@ -0,0 +1,56 @@ +warning: there were 2 feature warning(s); re-run with -feature for details + p.Iterable[Int] + p.Set[Int] + p.Seq[Int] + p.m.Set[Int] + p.m.Seq[Int] + private[m] p.m.ASet[Int] + p.i.Seq[Int] + private[i] p.i.ASet[Int] + private[i] p.i.ASeq[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Set[Int] + p.Iterable[Int] + p.Set[Int] + p.Iterable[Int] + p.Set[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Seq[Int] + p.Iterable[Int] + p.Seq[Int] + p.Iterable[Int] + p.Seq[Int] + p.Iterable[Int] + p.m.Set[Int] + p.Iterable[Int] + p.Set[Int] + p.Iterable[Int] + p.Iterable[Int] + p.Seq[Int] + p.Iterable[Int] + p.Seq[Int] + p.Iterable[Int] + private[p] p.ASet[Int] + private[p] p.AIterable[Int] + p.Iterable[Int] + p.i.Seq[Int] + private[p] p.AIterable[Int] + List[Nothing] + scala.collection.immutable.Vector[Nothing] + scala.collection.immutable.Iterable[(Int, Int)] + scala.collection.immutable.Set[Int] + Seq[Int] + Array[Int] + scala.collection.AbstractSet[Int] + Comparable[java.lang.String] + scala.collection.immutable.LinearSeq[Int] + Iterable[Int] diff --git a/test/files/run/inferred-type-constructors.scala b/test/files/run/inferred-type-constructors.scala new file mode 100644 index 0000000000..79a8653f68 --- /dev/null +++ b/test/files/run/inferred-type-constructors.scala @@ -0,0 +1,125 @@ +package p { + trait TCon[+CC[X]] { + def fPublic: CC[Int] = ??? + private[p] def fPackagePrivate: CC[Int] = ??? + protected[p] def fPackageProtected: CC[Int] = ??? + } + trait Iterable[+A] extends TCon[Iterable] + trait Set[A] extends Iterable[A] with TCon[Set] + trait Seq[+A] extends Iterable[A] with TCon[Seq] + + private[p] abstract class AIterable[+A] extends Iterable[A] + private[p] abstract class ASeq[+A] extends AIterable[A] with Seq[A] + private[p] abstract class ASet[A] extends AIterable[A] with Set[A] + + package m { + private[m] abstract class ASeq[A] extends p.ASeq[A] with Seq[A] + private[m] abstract class ASet[A] extends p.ASet[A] with Set[A] + trait Set[A] extends p.Set[A] with TCon[Set] + trait Seq[A] extends p.Seq[A] with TCon[Seq] + trait BitSet extends ASet[Int] + trait IntSeq extends ASeq[Int] + } + + package i { + private[i] abstract class ASeq[+A] extends p.ASeq[A] with Seq[A] + private[i] abstract class ASet[A] extends p.ASet[A] with Set[A] + trait Set[A] extends p.Set[A] with TCon[Set] + trait Seq[+A] extends p.Seq[A] with TCon[Seq] + trait BitSet extends ASet[Int] + trait IntSeq extends ASeq[Int] + } +} + +object Test { + import scala.reflect.runtime.universe._ + // Complicated by the absence of usable type constructor type tags. + def extract[A, CC[X]](xs: CC[A]): CC[A] = xs + def whatis[T: TypeTag](x: T): Unit = { + val tpe = typeOf[T] + val access = tpe.typeSymbol.asInstanceOf[scala.reflect.internal.HasFlags].accessString.replaceAllLiterally("package ", "") + println(f"$access%15s $tpe") + } + + trait IntIterable extends p.Iterable[Int] + trait IntSet extends p.Set[Int] + trait IntSeq extends p.Seq[Int] + + trait MutableIntSet extends p.m.Set[Int] + trait MutableIntSeq extends p.m.Seq[Int] + + trait ImmutableIntSet extends p.i.Set[Int] + trait ImmutableIntSeq extends p.i.Seq[Int] + + def f1: IntIterable = null + def f2: IntSet = null + def f3: IntSeq = null + + def g1: MutableIntSet = null + def g2: MutableIntSeq = null + def g3: p.m.BitSet = null + + def h1: ImmutableIntSeq = null + def h2: p.i.BitSet = null + def h3: p.i.IntSeq = null + + def main(args: Array[String]): Unit = { + whatis(extract(f1)) + whatis(extract(f2)) + whatis(extract(f3)) + whatis(extract(g1)) + whatis(extract(g2)) + whatis(extract(g3)) + whatis(extract(h1)) + whatis(extract(h2)) + whatis(extract(h3)) + + whatis(extract(if (true) f1 else f2)) + whatis(extract(if (true) f1 else f3)) + whatis(extract(if (true) f1 else g1)) + whatis(extract(if (true) f1 else g2)) + whatis(extract(if (true) f1 else g3)) + whatis(extract(if (true) f1 else h1)) + whatis(extract(if (true) f1 else h2)) + whatis(extract(if (true) f1 else h3)) + whatis(extract(if (true) f2 else f3)) + whatis(extract(if (true) f2 else g1)) + whatis(extract(if (true) f2 else g2)) + whatis(extract(if (true) f2 else g3)) + whatis(extract(if (true) f2 else h1)) + whatis(extract(if (true) f2 else h2)) + whatis(extract(if (true) f2 else h3)) + whatis(extract(if (true) f3 else g1)) + whatis(extract(if (true) f3 else g2)) + whatis(extract(if (true) f3 else g3)) + whatis(extract(if (true) f3 else h1)) + whatis(extract(if (true) f3 else h2)) + whatis(extract(if (true) f3 else h3)) + whatis(extract(if (true) g1 else g2)) + whatis(extract(if (true) g1 else g3)) + whatis(extract(if (true) g1 else h1)) + whatis(extract(if (true) g1 else h2)) + whatis(extract(if (true) g1 else h3)) + whatis(extract(if (true) g2 else g3)) + whatis(extract(if (true) g2 else h1)) + whatis(extract(if (true) g2 else h2)) + whatis(extract(if (true) g2 else h3)) + whatis(extract(if (true) g3 else h1)) + whatis(extract(if (true) g3 else h2)) + whatis(extract(if (true) g3 else h3)) + whatis(extract(if (true) h1 else h2)) + whatis(extract(if (true) h1 else h3)) + whatis(extract(if (true) h2 else h3)) + + whatis(extract(Nil)) + whatis(extract(Vector())) + whatis(extract(Map[Int,Int]())) + whatis(extract(Set[Int]())) + whatis(extract(Seq[Int]())) + whatis(extract(Array[Int]())) + whatis(extract(scala.collection.immutable.BitSet(1))) + whatis(extract("abc")) + whatis(extract(if (true) Stream(1) else List(1))) + whatis(extract(if (true) Seq(1) else Set(1))) + } +} |