Scala Programming Language
  1. Scala Programming Language
  2. SI-6570

Change Seq alias from collection.Seq to collection.immutable.Seq

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 2.12.0-M1
    • Component/s: Collections
    • Labels:
      None

      Description

      Seq pointing to collection.Seq is very dangerous, because it enables mutability leaking into an otherwise immutable API. It is very dangerous, because the "Scala story" is that all collections that one can use without import are immutable. Even very experienced developers don't know or simply forget that Seq just aliases collection.Seq, which means one could easily pass a mutable Seq or Array for a parameter annotated with Seq.

      See the scala-internal mailing list for more details ...

        Activity

        Hide
        Viktor Klang added a comment -

        Exhibit A:

        In predef:

        type Map[A, +B] = immutable.Map[A, B]
        type Set[A] = immutable.Set[A]

        exercise for the reader:

        type Seq[A] = ???

        Show
        Viktor Klang added a comment - Exhibit A: In predef: type Map [A, +B] = immutable.Map [A, B] type Set [A] = immutable.Set [A] exercise for the reader: type Seq [A] = ???
        Hide
        Seth Tisue added a comment -
        Show
        Seth Tisue added a comment - the scala-internals thread is https://groups.google.com/d/topic/scala-internals/g_-gIWgB8Os/discussion
        Hide
        Martin Odersky added a comment -

        There will be likely a collections overhaul for 2.11. I think a change of this magnitude is definitely too late for 2.10.0 (it IS a big change, because it affects varags handling). Furthermore, this is neither a regression not a catastrophic failure of a new feature. So I do not think it is a blocker for 2.10.

        Show
        Martin Odersky added a comment - There will be likely a collections overhaul for 2.11. I think a change of this magnitude is definitely too late for 2.10.0 (it IS a big change, because it affects varags handling). Furthermore, this is neither a regression not a catastrophic failure of a new feature. So I do not think it is a blocker for 2.10.
        Hide
        Heiko Seeberger added a comment -

        Additionally we should also redirect the following:

        type Traversable[+A] = scala.collection.immutable.Traversable[A]

        type Iterable[+A] = scala.collection.immutable.Iterable[A]

        type IndexedSeq[+A] = scala.collection.immutable.IndexedSeq[A]

        Show
        Heiko Seeberger added a comment - Additionally we should also redirect the following: type Traversable [+A] = scala.collection.immutable.Traversable [A] type Iterable [+A] = scala.collection.immutable.Iterable [A] type IndexedSeq [+A] = scala.collection.immutable.IndexedSeq [A]
        Hide
        Denys Shabalin added a comment -

        I've recently learned that default Seq is mutable myself and that was extremely confusing.

        Show
        Denys Shabalin added a comment - I've recently learned that default Seq is mutable myself and that was extremely confusing.

          People

          • Assignee:
            Unassigned
            Reporter:
            Heiko Seeberger
          • Votes:
            9 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated:

              Development