Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.1, Scala 2.10.0
    • Fix Version/s: Scala 2.10.0-M3, Scala 2.10.0
    • Component/s: None
    • Labels:
      None

      Description

      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
      

        Attachments

          Activity

          Hide
          olegych Oleg Aleshko added a comment -

          also

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

          Show
          olegych Oleg Aleshko added a comment - also scala> Vector(1).view.updated(0,2).toList res21: List[Int] = List(2, 1)
          Hide
          jsuereth Josh Suereth added a comment -

          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)
          

          Show
          jsuereth Josh Suereth added a comment - 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)
          Hide
          jsuereth Josh Suereth added a comment -

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

          Show
          jsuereth Josh Suereth added a comment - Yep, iterator.patch is broken when "from = 0". I think I have fix.
          Hide
          arya Arya Irani added a comment -

          Thanks Josh!

          Show
          arya Arya Irani added a comment - Thanks Josh!

            People

            • Assignee:
              jsuereth Josh Suereth
              Reporter:
              refried Arya Irani
            • Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: