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

fix mutable.HashSet.addAll: remove redundant call to super method #8192

Merged
merged 1 commit into from Jul 22, 2019

Conversation

miteshaghera
Copy link
Contributor

@miteshaghera miteshaghera commented Jul 2, 2019

Removed redundant call to super method.

Fixes scala/bug#11601

@scala-jenkins scala-jenkins added this to the 2.13.1 milestone Jul 2, 2019
@dwijnand
Copy link
Member

dwijnand commented Jul 2, 2019

Hey, @miteshaghera. Thanks for the PR! Do you think you could add a unit test that validates this fix and ensures it doesn't regress, please?

@miteshaghera
Copy link
Contributor Author

@dwijnand Give me some time I'll update unit test which validate this PR.

@diesalbla diesalbla added the library:collections PRs involving changes to the standard collection library label Jul 2, 2019
miteshaghera pushed a commit to miteshaghera/scala that referenced this pull request Jul 3, 2019
Copy link
Member

@dwijnand dwijnand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dwijnand dwijnand added the welcome hello new contributor! label Jul 3, 2019
@SethTisue
Copy link
Member

could you squash this into a single commit?

this looks otherwise ready to merge.

@som-snytt
Copy link
Contributor

For a test, I'd suggest something direct:

package once

import collection.IterableOnce

class OnceOnly extends IterableOnce[Int] {
  override def knownSize = 1
  private var iterated: Boolean = false
  override def iterator = {
    assert(!iterated)
    iterated = true
    new Iterator[Int] {
      private var v = Option(42)
      override def hasNext = v.nonEmpty
      override def next() = { val res = v.get ; v = None ; res }
    }
  }
}

object Test extends App {
  val hs = collection.mutable.HashSet.empty[Int]
  hs.addAll(new OnceOnly)
}

Putting it in junit form is left as an exercise for the reader.

@som-snytt
Copy link
Contributor

som-snytt commented Jul 3, 2019

Looking at what I wrote, I'm not sure if knownSize should be zero after the iterator is exhausted?

Ideally, all the API taking an IterableOnce would be tested that it obeys the contract. Is it a contract if it's just a handshake between two good ole boys that they promise not to call it twice?

@miteshaghera
Copy link
Contributor Author

For a test, I'd suggest something direct:

package once

import collection.IterableOnce

class OnceOnly extends IterableOnce[Int] {
  override def knownSize = 1
  private var iterated: Boolean = false
  override def iterator = {
    assert(!iterated)
    iterated = true
    new Iterator[Int] {
      private var v = Option(42)
      override def hasNext = v.nonEmpty
      override def next() = { val res = v.get ; v = None ; res }
    }
  }
}

object Test extends App {
  val hs = collection.mutable.HashSet.empty[Int]
  hs.addAll(new OnceOnly)
}

Putting it in junit form is left as an exercise for the reader.

Thanks, I'll add this is as another test as well. Can I use your snippet?

@som-snytt
Copy link
Contributor

Yes, please use it in any way if it's helpful.

@SethTisue SethTisue changed the title removed redundant call to super method fix mutable.HashSet.addAll: remove redundant call to super method Jul 4, 2019
@miteshaghera
Copy link
Contributor Author

could you squash this into a single commit?

this looks otherwise ready to merge.

I squashed the commits.

@joshlemer joshlemer mentioned this pull request Jul 13, 2019
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @miteshaghera!

@lrytz lrytz merged commit e902fc8 into scala:2.13.x Jul 22, 2019
@miteshaghera miteshaghera deleted the 2.13.x branch July 27, 2019 06:24
@szeiger szeiger added the release-notes worth highlighting in next release notes label Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library:collections PRs involving changes to the standard collection library release-notes worth highlighting in next release notes welcome hello new contributor!
Projects
None yet
8 participants