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

ListBuffer.readOnly destroys List immutability #8251

Closed
scabug opened this issue Feb 8, 2014 · 7 comments
Closed

ListBuffer.readOnly destroys List immutability #8251

scabug opened this issue Feb 8, 2014 · 7 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Feb 8, 2014

Example:

scala> val buf = scala.collection.mutable.ListBuffer[Int](1, 2)
buf: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2)

scala> def f(): List[Int] = buf.readOnly
f: ()List[Int]

scala> val innocent = f()
innocent: List[Int] = List(1, 2)

scala> buf ++= (1 to 100)
res4: buf.type = ListBuffer(1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)

scala> innocent
res5: List[Int] = List(1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)

This was discussed long ago there:
https://groups.google.com/d/msg/scala-internals/g_-gIWgB8Os/kWazrALbLKEJ

The summary of discussion:

martin> Is it used somewhere in the standard library? I agree that if possible we should deprecate it.
martin> As far as I can tell, the intent was that it provides a view. So, the implementation
def readOnly = this
Is perfectly fine.

@scabug
Copy link
Author

scabug commented Feb 8, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8251?orig=1
Reporter: @pavelpavlov
Affected Versions: 2.11.0-M8

@scabug
Copy link
Author

scabug commented Feb 9, 2014

@pavelpavlov said:
scala/scala#3489

@scabug
Copy link
Author

scabug commented Feb 25, 2014

@adriaanm said:
Deprecation: scala/scala#3582

@scabug
Copy link
Author

scabug commented Nov 21, 2014

@som-snytt said:
Disposal: scala/scala#4140

@scabug
Copy link
Author

scabug commented Nov 21, 2014

@gkossakowski said:
Fixed by removing ListBuffer.readOnly method.

@scabug scabug closed this as completed Nov 21, 2014
@scabug
Copy link
Author

scabug commented Nov 22, 2014

@paulp said:
As explained at https://gist.github.com/paulp/9081797 and scala/scala#3489

Removing readOnly barely begins to address the problem.

@scabug
Copy link
Author

scabug commented Nov 22, 2014

@som-snytt said:
"ListBuffer.readOnly also leaks List immutability."

@scabug scabug added the has PR label Apr 7, 2017
@scabug scabug added this to the 2.12.0-M1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants