Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
scabug opened this issue Oct 25, 2012 · 9 comments
Closed

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

scabug opened this issue Oct 25, 2012 · 9 comments

Comments

@scabug
Copy link

scabug commented Oct 25, 2012

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 ...

@scabug
Copy link
Author

scabug commented Oct 25, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6570?orig=1
Reporter: @hseeberger

@scabug
Copy link
Author

scabug commented Oct 25, 2012

@viktorklang said:
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] = ???

@scabug
Copy link
Author

scabug commented Oct 25, 2012

@scabug
Copy link
Author

scabug commented Nov 3, 2012

@odersky said:
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.

@scabug
Copy link
Author

scabug commented Jan 29, 2014

@hseeberger said:
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]

@scabug
Copy link
Author

scabug commented Jan 30, 2014

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

@scabug
Copy link
Author

scabug commented Dec 2, 2014

Jeff Shaw (shawjef3) said (edited on Dec 2, 2014 3:53:56 AM UTC):
I was thinking about how I would solve this. My idea is to make varargs be an Array instead of a Seq, since it's really an Array, anyhow. We wouldn't lose any performance, and the fact that the argument collection is mutable wouldn't be hidden or surprising. After that it's trivial to replace collections.Seq with immutable.Seq.

If we must have Seq methods available to vararg values, an implicit conversion from scala.Array to mutable.Seq would be enough.

@scabug
Copy link
Author

scabug commented Dec 10, 2015

@SethTisue said:
We can't change this for 2.12, but I consider it very high priority for 2.13.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@SethTisue
Copy link
Member

This. Is. Happening. scala/collection-strawman#149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants