From f998399a417f83766e18ee1789773734167e7c9c Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Wed, 20 Mar 2024 22:27:06 +0100 Subject: [PATCH 1/2] Add more methods in `SeqViewOps` --- scala2-library-cc/src/scala/collection/Seq.scala | 4 ++-- scala2-library-cc/src/scala/collection/SeqView.scala | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scala2-library-cc/src/scala/collection/Seq.scala b/scala2-library-cc/src/scala/collection/Seq.scala index aac1439668c4..9a34e5e144fc 100644 --- a/scala2-library-cc/src/scala/collection/Seq.scala +++ b/scala2-library-cc/src/scala/collection/Seq.scala @@ -118,7 +118,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * Note that :-ending operators are right associative (see example). * A mnemonic for `+:` vs. `:+` is: the COLon goes on the COLlection side. */ - @`inline` final def +: [B >: A](elem: B): CC[B] = prepended(elem) + @`inline` override final def +: [B >: A](elem: B): CC[B] = prepended(elem) /** A copy of this $coll with an element appended. * @@ -148,7 +148,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self => * Note that :-ending operators are right associative (see example). * A mnemonic for `+:` vs. `:+` is: the COLon goes on the COLlection side. */ - @`inline` final def :+ [B >: A](elem: B): CC[B] = appended(elem) + @`inline` override final def :+ [B >: A](elem: B): CC[B] = appended(elem) /** As with `:++`, returns a new collection containing the elements from the left operand followed by the * elements from the right operand. diff --git a/scala2-library-cc/src/scala/collection/SeqView.scala b/scala2-library-cc/src/scala/collection/SeqView.scala index c2c4a6e5da21..34405e06eedb 100644 --- a/scala2-library-cc/src/scala/collection/SeqView.scala +++ b/scala2-library-cc/src/scala/collection/SeqView.scala @@ -65,6 +65,10 @@ trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] { def distinctBy[B](f: A -> B): C^{this} = assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.") ??? + + // The following methods are copied from [[SeqOps]]. + @`inline` def +: [B >: A](elem: B): CC[B]^{this} = prepended(elem) + @`inline` def :+ [B >: A](elem: B): CC[B]^{this} = appended(elem) // ------------------- def reverseIterator: Iterator[A]^{this} = reversed.iterator From 0107724bf9147bfbddfa9ba6d739a603f2c58404 Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Fri, 22 Mar 2024 13:52:03 +0100 Subject: [PATCH 2/2] Add testcase for #19988 --- tests/pos/i19988.scala | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/pos/i19988.scala diff --git a/tests/pos/i19988.scala b/tests/pos/i19988.scala new file mode 100644 index 000000000000..4879f814d6a0 --- /dev/null +++ b/tests/pos/i19988.scala @@ -0,0 +1,7 @@ +import collection.IndexedSeqView +object Hello extends App { + def foo(view: IndexedSeqView[Int]): Unit = + val x1 = 1 +: view + val x2 = view :+ 1 +} +