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

SeqView cannot map with breakOut #6709

Closed
scabug opened this issue Nov 24, 2012 · 9 comments
Closed

SeqView cannot map with breakOut #6709

scabug opened this issue Nov 24, 2012 · 9 comments

Comments

@scabug
Copy link

scabug commented Nov 24, 2012

0.until(5).view.map { 1 + _ }(collection.breakOut(Set.canBuildFrom))
java.lang.ClassCastException: scala.collection.SeqViewLike$$anon$3 cannot be cast to scala.collection.immutable.Set
        at .<init>(<console>:8)
        at .<clinit>(<console>)
        at .<init>(<console>:11)
        at .<clinit>(<console>)
        at $print(<console>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)

        at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:914)

        at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:546)
        at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:577)
        at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:543)
        at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:694)
        at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:745)
        at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:651)
        at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:542)
        at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:550)
        at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
        at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:851)
        at xsbt.ConsoleInterface.run(ConsoleInterface.scala:57)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:73)
        at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:64)
        at sbt.Console.console0$1(Console.scala:23)
        at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:24)
        at sbt.TrapExit$.executeMain$1(TrapExit.scala:33)
        at sbt.TrapExit$$anon$1.run(TrapExit.scala:42)
@scabug
Copy link
Author

scabug commented Nov 24, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6709?orig=1
Reporter: @Atry
Affected Versions: 2.9.2, 2.10.0-RC2, 2.11.1

@scabug
Copy link
Author

scabug commented Nov 25, 2012

@Atry said:
When mapping a SeqView with a non-default CanBuildFrom, I expect it forces all elements and become that collection.

@scabug
Copy link
Author

scabug commented Jan 20, 2013

@Sciss said (edited on Jan 20, 2013 5:02:17 PM UTC):
Another example (showing that it also has this casting problem without custom CanBuild): http://stackoverflow.com/questions/14426653/collections-code-involving-mutable-indexedseq-view-take-and-grouped-throws-cl/14426876

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Feb 11, 2014

Gilles Scouvart (GillesScouvart) said:
This can also show up in unexpected locations, like here:

"a b c d".split(" ").view.grouped(2).map{_ mkString ","} foreach println

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@retronym said:
My recommendation is to avoid using .view when .iterator will do.

 "a b c d".split(" ").iterator.grouped(2).map{_ mkString ","} foreach println
a,b
c,d

I fixed a number of view bugs in 2.11 but this one still persists.

@scabug
Copy link
Author

scabug commented May 23, 2014

Jacek Królikowski (nietaki) said:
Unfortunately there are situations, where .iterator won't do the trick.

{code}scala> Array(4,3,2,1).view(0,2).sorted
java.lang.ClassCastException: scala.collection.SeqViewLike$$anon$1 cannot be cast to scala.collection.mutable.IndexedSeqView
{code}

@scabug
Copy link
Author

scabug commented May 23, 2014

@retronym said:
Yep, views are more powerful than iterators. I guess my followup suggestion is to avoid using views on Array and String.

scala> Array(4,3,2,1).toIndexedSeq.view(0,2).sorted
res2: scala.collection.SeqView[Int,scala.collection.immutable.IndexedSeq[Int]] = SeqViewSC(...)

scala> .force
res3: scala.collection.immutable.IndexedSeq[Int] = Vector(3, 4)

@NthPortal
Copy link

Should be fixed in the 2.13 collections rework

@SethTisue SethTisue modified the milestones: Backlog, 2.13.0-M4 Jun 15, 2018
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