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

GroupBy in views returns wrong result in 2.9.x #4660

Closed
scabug opened this issue May 31, 2011 · 2 comments
Closed

GroupBy in views returns wrong result in 2.9.x #4660

scabug opened this issue May 31, 2011 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 31, 2011

The following test fails (It works in 2.8.1.final):

val traversable = 1 to 30 map {_.toString}
def normalize(m:Map[Char,Traversable[String]]) = m.map{case (k,v) => (k,v.toList)}
val groupedFromView = (traversable view).groupBy(_(0))
val groupedFromStrict = traversable.groupBy(_(0))

assert(normalize(groupedFromView) == normalize(groupedFromStrict))

groupBy throws an exception in 2.9.0 but in 2.9.0.1 just returns the wrong value.

Essentially what is happening is the groups are formed correctly but the values in each group are always the entire collection. I believe the bug is in TraversableViewLike:170. Look at the implementation:

  override def groupBy[K](f: A => K): immutable.Map[K, This] =
    thisSeq.groupBy(f).mapValues(xs => newForced(thisSeq))

The section newForced(thisSeq) probably should be newForced(xs).

I have tried this in a subclass and the fix worked.

@scabug
Copy link
Author

scabug commented May 31, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4660?orig=1
Reporter: Jesse Eichar (jesseeichar)
Affected Versions: 2.9.0

@scabug
Copy link
Author

scabug commented Jun 12, 2011

Commit Message Bot (anonymous) said:
(extempore in r25074) Fix for wrong results from groupBy on views. Closes #4660, no review.

@scabug scabug closed this as completed Jun 12, 2011
@scabug scabug added this to the 2.9.1 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