diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 0c308a4ba6d0..ac7b4ef39604 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -242,10 +242,12 @@ class PlainPrinter(_ctx: Context) extends Printer { val refsText = if showAsCap then rootSetText else toTextCaptureSet(refs) toTextCapturing(parent, refsText, boxText) case tp @ RetainingType(parent, refs) => - val refsText = refs match - case ref :: Nil if ref.symbol == defn.captureRoot => rootSetText - case _ => toTextRetainedElems(refs) - toTextCapturing(parent, refsText, "") ~ Str("R").provided(printDebug) + if Feature.ccEnabledSomewhere then + val refsText = refs match + case ref :: Nil if ref.symbol == defn.captureRoot => rootSetText + case _ => toTextRetainedElems(refs) + toTextCapturing(parent, refsText, "") ~ Str("R").provided(printDebug) + else toText(parent) case tp: PreviousErrorType if ctx.settings.XprintTypes.value => "" // do not print previously reported error message because they may try to print this error type again recuresevely case tp: ErrorType => diff --git a/scala2-library-cc/src/scala/collection/Seq.scala b/scala2-library-cc/src/scala/collection/Seq.scala index 65927154c4b6..aac1439668c4 100644 --- a/scala2-library-cc/src/scala/collection/Seq.scala +++ b/scala2-library-cc/src/scala/collection/Seq.scala @@ -206,7 +206,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * * @return a new $coll consisting of all the elements of this $coll without duplicates. */ - def distinct: C = distinctBy(identity) + override def distinct: C = distinctBy(identity) /** Selects all the elements of this $coll ignoring the duplicates as determined by `==` after applying * the transforming function `f`. @@ -215,7 +215,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * @tparam B the type of the elements after being transformed by `f` * @return a new $coll consisting of all the elements of this $coll without duplicates. */ - def distinctBy[B](f: A -> B): C = fromSpecific(new View.DistinctBy(this, f)) + override def distinctBy[B](f: A -> B): C = fromSpecific(new View.DistinctBy(this, f)) /** Returns new $coll with elements in reversed order. * @@ -293,7 +293,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * all elements of this $coll followed by the minimal number of occurrences of `elem` so * that the resulting collection has a length of at least `len`. */ - def padTo[B >: A](len: Int, elem: B): CC[B] = iterableFactory.from(new View.PadTo(this, len, elem)) + override def padTo[B >: A](len: Int, elem: B): CC[B] = iterableFactory.from(new View.PadTo(this, len, elem)) /** Computes the length of the longest segment that starts from the first element * and whose elements all satisfy some predicate. @@ -544,7 +544,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * // List(b, b, a) * }}} */ - def permutations: Iterator[C] = + override def permutations: Iterator[C] = if (isEmpty) Iterator.single(coll) else new PermutationsItr @@ -585,7 +585,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * // List(b, a) * }}} */ - def combinations(n: Int): Iterator[C] = + override def combinations(n: Int): Iterator[C] = if (n < 0 || n > size) Iterator.empty else new CombinationsItr(n) @@ -759,7 +759,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * List("Bobby", "Bob", "John", "Steve", "Tom") * }}} */ - def sortWith(lt: (A, A) => Boolean): C = sorted(Ordering.fromLessThan(lt)) + override def sortWith(lt: (A, A) => Boolean): C = sorted(Ordering.fromLessThan(lt)) /** Sorts this $coll according to the Ordering which results from transforming * an implicitly given Ordering with a transformation function. @@ -786,7 +786,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * res0: Array[String] = Array(The, dog, fox, the, lazy, over, brown, quick, jumped) * }}} */ - def sortBy[B](f: A => B)(implicit ord: Ordering[B]): C = sorted(ord on f) + override def sortBy[B](f: A => B)(implicit ord: Ordering[B]): C = sorted(ord on f) /** Produces the range of all indices of this sequence. * $willForceEvaluation @@ -944,7 +944,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * except that `replaced` elements starting from `from` are replaced * by all the elements of `other`. */ - def patch[B >: A](from: Int, other: IterableOnce[B]^, replaced: Int): CC[B] = + override def patch[B >: A](from: Int, other: IterableOnce[B]^, replaced: Int): CC[B] = iterableFactory.from(new View.Patched(this, from, other, replaced)) .unsafeAssumePure // assume pure OK since iterableFactory.from is eager for Seq @@ -957,7 +957,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * lazy collection this exception may be thrown at a later time or not at * all (if the end of the collection is never evaluated). */ - def updated[B >: A](index: Int, elem: B): CC[B] = { + override def updated[B >: A](index: Int, elem: B): CC[B] = { if(index < 0) throw new IndexOutOfBoundsException(index.toString) val k = knownSize if(k >= 0 && index >= k) throw new IndexOutOfBoundsException(index.toString) diff --git a/scala2-library-cc/src/scala/collection/SeqView.scala b/scala2-library-cc/src/scala/collection/SeqView.scala index c66d7b5f4694..c2c4a6e5da21 100644 --- a/scala2-library-cc/src/scala/collection/SeqView.scala +++ b/scala2-library-cc/src/scala/collection/SeqView.scala @@ -30,11 +30,43 @@ trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] { def length: Int def apply(x: Int): A def appended[B >: A](elem: B): CC[B]^{this} - def updated[B >: A](index: Int, elem: B): CC[B]^{this} def prepended[B >: A](elem: B): CC[B]^{this} def reverse: C^{this} def sorted[B >: A](implicit ord: Ordering[B]): C^{this} + // Placeholder implementations for the corresponding methods in SeqOps. + // This is needed due to the change in the class hierarchy in cc stdlib. + // See #19660 and #19819. + // ------------------- + def updated[B >: A](index: Int, elem: B): CC[B]^{this} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + def padTo[B >: A](len: Int, elem: B): CC[B]^{this} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + def patch[B >: A](from: Int, other: IterableOnce[B]^, replaced: Int): CC[B]^{this, other} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + def combinations(n: Int): Iterator[C^{this}]^{this} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + def sortBy[B](f: A => B)(implicit ord: Ordering[B]): C^{this, f} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + def sortWith(lt: (A, A) => Boolean): C^{this, lt} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + def permutations: Iterator[C^{this}]^{this} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + def distinct: C^{this} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + def distinctBy[B](f: A -> B): C^{this} = + assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") + ??? + // ------------------- + def reverseIterator: Iterator[A]^{this} = reversed.iterator } @@ -46,15 +78,6 @@ trait SeqView[+A] extends SeqViewOps[A, View, View[A]] with View[A] { override def map[B](f: A => B): SeqView[B]^{this, f} = new SeqView.Map(this, f) override def appended[B >: A](elem: B): SeqView[B]^{this} = new SeqView.Appended(this, elem) - // Copied from SeqOps. This is needed due to the change of class hierarchy in stdlib. - // See #19660. - override def updated[B >: A](index: Int, elem: B): View[B]^{this} = { - if(index < 0) throw new IndexOutOfBoundsException(index.toString) - val k = knownSize - if(k >= 0 && index >= k) throw new IndexOutOfBoundsException(index.toString) - iterableFactory.from(new View.Updated(this, index, elem)) - } - override def prepended[B >: A](elem: B): SeqView[B]^{this} = new SeqView.Prepended(elem, this) override def reverse: SeqView[A]^{this} = new SeqView.Reverse(this) override def take(n: Int): SeqView[A]^{this} = new SeqView.Take(this, n) diff --git a/scala2-library-cc/src/scala/collection/generic/IsSeq.scala b/scala2-library-cc/src/scala/collection/generic/IsSeq.scala index 7b5e50499c0c..420a81d94ab4 100644 --- a/scala2-library-cc/src/scala/collection/generic/IsSeq.scala +++ b/scala2-library-cc/src/scala/collection/generic/IsSeq.scala @@ -54,24 +54,22 @@ object IsSeq { seqOpsIsSeqVal.asInstanceOf[IsSeq[CC0[A0]] { type A = A0; type C = CC0[A0] }] /** !!! Under cc, views are not Seqs and can't use SeqOps. - * So this should be renamed to seqViewIsIterable - */ - implicit def seqViewIsSeq[CC0[X] <: SeqView[X], A0]: IsIterable[CC0[A0]] { type A = A0; type C = View[A0] } = - new IsIterable[CC0[A0]] { - type A = A0 - type C = View[A] - def apply(coll: CC0[A0]): IterableOps[A0, View, View[A0]] = coll - } + * Therefore, [[seqViewIsSeq]] now returns an [[IsIterable]]. + * The helper method [[seqViewIsSeq_]] is added to make the binary compatible. + */ + @annotation.targetName("seqViewIsSeq") + @annotation.publicInBinary + private[IsSeq] def seqViewIsSeq_[CC0[X] <: SeqView[X], A0]: IsSeq[CC0[A0]] { type A = A0; type C = View[A0] } = ??? + implicit inline def seqViewIsSeq[CC0[X] <: SeqView[X], A0]: IsIterable[CC0[A0]] { type A = A0; type C = View[A0] } = seqViewIsSeq_[CC0, A0].asInstanceOf /** !!! Under cc, views are not Seqs and can't use SeqOps. - * So this should be renamed to stringViewIsIterable - */ - implicit val stringViewIsSeq: IsIterable[StringView] { type A = Char; type C = View[Char] } = - new IsIterable[StringView] { - type A = Char - type C = View[Char] - def apply(coll: StringView): IterableOps[Char, View, View[Char]] = coll - } + * Therefore, [[stringViewIsSeq]] now returns an [[IsIterable]]. + * The helper method [[stringViewIsSeq__]] is added to make the binary compatible. + */ + @annotation.targetName("stringViewIsSeq") + @annotation.publicInBinary + private[IsSeq] val stringViewIsSeq_ : IsSeq[StringView] { type A = Char; type C = View[Char] } = ??? + inline implicit def stringViewIsSeq: IsIterable[StringView] { type A = Char; type C = View[Char] } = stringViewIsSeq_.asInstanceOf implicit val stringIsSeq: IsSeq[String] { type A = Char; type C = String } = new IsSeq[String] { diff --git a/tests/run/enrich-gentraversable.scala b/tests/run/enrich-gentraversable.scala index 43514e5a5136..887a6aea7983 100644 --- a/tests/run/enrich-gentraversable.scala +++ b/tests/run/enrich-gentraversable.scala @@ -3,6 +3,7 @@ import scala.language.postfixOps object Test extends App { import scala.collection.generic.IsIterable + import scala.collection.generic.IsSeq.seqViewIsSeq import scala.collection.{BuildFrom, Iterable, IterableOps, View} import scala.collection.immutable.TreeMap