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

clear() on a mutable.SetLike does not remove all elements #9497

Closed
scabug opened this issue Sep 29, 2015 · 5 comments
Closed

clear() on a mutable.SetLike does not remove all elements #9497

scabug opened this issue Sep 29, 2015 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 29, 2015

When implementing my own mutable Set with mutable.SetLike, the clear method does not remove all elements in some cases. It only happens when I have certain strings in my Set, in this case: "EXPOSEDNODE" and "CONNECTABLE".

import collection.mutable

class MySet(self:mutable.Set[String]) extends mutable.Set[String] with mutable.SetLike[String, MySet]{

  override def -=(elem: String) = {self -= elem; this}
  override def +=(elem: String) = {self += elem; this}

  override def empty = new MySet(self.empty)
  override def iterator = self.iterator
  override def contains(elem: String) = self.contains(elem)
}

val s = new MySet(mutable.Set("EXPOSEDNODE", "CONNECTABLE"))
s.clear()
println(s) // prints "Set(CONNECTABLE)"
@scabug
Copy link
Author

scabug commented Sep 29, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9497?orig=1
Reporter: Felix Dietze (man)
Affected Versions: 2.11.7
See #7269

@scabug
Copy link
Author

scabug commented Sep 29, 2015

Felix Dietze (man) said:
It seems like this is related to:

scala> val s = collection.mutable.Set("EXPOSEDNODE", "CONNECTABLE"); s.foreach(s -=)
s: scala.collection.mutable.Set[String] = Set(CONNECTABLE)

As the default implementation of SetLike.clear() is foreach(-=) SetLike.scala

@scabug
Copy link
Author

scabug commented Sep 30, 2015

@SethTisue said:
Rex, provisionally assigning to you, on the assumption this is probably up your alley

@scabug
Copy link
Author

scabug commented Oct 21, 2015

@ruippeixotog said:
This bug has the same cause as #7269, but then only retain() was fixed. I have just submitted a pull request in which clear() is fixed to have the same structure as retain().

@scabug
Copy link
Author

scabug commented Nov 12, 2015

@adriaanm said:
scala/scala#4810

@scabug scabug closed this as completed Nov 12, 2015
@scabug scabug added this to the 2.11.8 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants