Skip to content

Commit bfdd235

Browse files
authored
Add more methods in SeqViewOps (#19993)
fixes #19988 The issue is caused by the change of class hierarchy in Scala 2 library CC: `SeqView` no longer extends `SeqOps`. To fix this we have to copy methods from `SeqOps` to `SeqViewOps`. Similar to what is done in #19873.
2 parents 53aa32a + 0107724 commit bfdd235

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

scala2-library-cc/src/scala/collection/Seq.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
118118
* Note that :-ending operators are right associative (see example).
119119
* A mnemonic for `+:` vs. `:+` is: the COLon goes on the COLlection side.
120120
*/
121-
@`inline` final def +: [B >: A](elem: B): CC[B] = prepended(elem)
121+
@`inline` override final def +: [B >: A](elem: B): CC[B] = prepended(elem)
122122

123123
/** A copy of this $coll with an element appended.
124124
*
@@ -148,7 +148,7 @@ trait SeqOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] { self =>
148148
* Note that :-ending operators are right associative (see example).
149149
* A mnemonic for `+:` vs. `:+` is: the COLon goes on the COLlection side.
150150
*/
151-
@`inline` final def :+ [B >: A](elem: B): CC[B] = appended(elem)
151+
@`inline` override final def :+ [B >: A](elem: B): CC[B] = appended(elem)
152152

153153
/** As with `:++`, returns a new collection containing the elements from the left operand followed by the
154154
* elements from the right operand.

scala2-library-cc/src/scala/collection/SeqView.scala

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] {
6565
def distinctBy[B](f: A -> B): C^{this} =
6666
assert(false, "This is a placeholder implementation in the capture checked Scala 2 library.")
6767
???
68+
69+
// The following methods are copied from [[SeqOps]].
70+
@`inline` def +: [B >: A](elem: B): CC[B]^{this} = prepended(elem)
71+
@`inline` def :+ [B >: A](elem: B): CC[B]^{this} = appended(elem)
6872
// -------------------
6973

7074
def reverseIterator: Iterator[A]^{this} = reversed.iterator

tests/pos/i19988.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import collection.IndexedSeqView
2+
object Hello extends App {
3+
def foo(view: IndexedSeqView[Int]): Unit =
4+
val x1 = 1 +: view
5+
val x2 = view :+ 1
6+
}
7+

0 commit comments

Comments
 (0)