Uploaded image for project: 'Swift'
  1. Swift
  2. SR-8279

Array - Fatal error: Index out of range

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Invalid
    • Component/s: None
    • Labels:

      Description

      Is receiving a fatal error in variable sized array when setting an object at an index desired behaviour?

       

      typealias Coordinate2D = Double
      typealias Point2D = [Coordinate2D]
      
      extension Array where Element == Coordinate2D {
        init(x: Coordinate2D, y: Coordinate2D) {
          self.init([x,y])
        }
      
        var x: Coordinate2D { get { return self[0] } set { self[0] = newValue } }
        var y: Coordinate2D { get { return self[1] } set { self[1] = newValue } }
      }
      
      var array = [Point2D]()
      
      let point = Point2D.init(x: 0, y: 0)
      array[0] = point // fatal error: index out of range
      

       

      Above code reproduces the issue in the playground resulting in indefinite execution time.

      The project reproducing the above mentioned error is in the attachments.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            Em Got
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: