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 craziness? #5328

Closed
scabug opened this issue Dec 19, 2011 · 5 comments

Comments

@scabug
Copy link

commented Dec 19, 2011

Ok:

val s = Seq(1)
val f = (s /: Seq(99))((s,c) => s.patch(0,Seq(c),1))

Won't compile:

val s = Seq(1).view
val f = (s /: Seq(99))((s,c) => s.patch(0,Seq(c),1))
// error: type mismatch;
// found   : scala.collection.SeqView[Int,Seq[_]]
// required: java.lang.Object with scala.collection.SeqView[Int,Seq[Int]]
//       val f = (s /: Seq(99))((s,c) => s.patch(0,Seq(c),1))
//                                              ^

Will compile, but weird results?

val s = Seq(1).view.asInstanceOf[Seq[Int]]
val f = (s /: Seq(99))((s,c) => s.patch(0,Seq(c),1))
f.length == f.toList.length  //  false???  1 == 2
@scabug

This comment has been minimized.

Copy link
Author

commented Dec 19, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5328?orig=1
Reporter: Arya Irani (refried)
Affected Versions: 2.9.1, 2.10.0
Other Milestones: 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

commented Dec 19, 2011

@OlegYch said:
also

scala> Vector(1).view.updated(0,2).toList
res21: List[Int] = List(2, 1)
@scabug

This comment has been minimized.

Copy link
Author

commented May 9, 2012

@jsuereth said:
I've isolated this to a faulty iterator.

I think it's relative to this line: override def iterator: Iterator[B] = self.iterator patch (from, patch.iterator, replaced)

You can see an example here:

scala> val view = Vector(1).view.updated(0,2)
view: scala.collection.SeqView[Int,Seq[_]] = SeqViewP(...)

scala> view(0)
res25: Int = 2

scala> view(1)
java.lang.IndexOutOfBoundsException: 1
	...


scala> view.length
res27: Int = 1

scala> view.iterator.toList
res28: List[Int] = List(2, 1)
@scabug

This comment has been minimized.

Copy link
Author

commented May 9, 2012

@jsuereth said:
Yep, iterator.patch is broken when "from = 0". I think I have fix.

@scabug

This comment has been minimized.

Copy link
Author

commented May 9, 2012

@refried said:
Thanks Josh!

@scabug scabug closed this May 9, 2012

@scabug scabug added this to the 2.10.0-M3 milestone Apr 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.