The Array.sort() method should return a sorted array

Originator:sw
Number:rdar://17225190 Date Originated:08-Jun-2014 11:06 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Swift 1.0
Classification:Other Bug Reproducible:Always
 
Summary:

The Swift Standard Library Reference lists five Algorithm methods on Array: map, filter, reduce, reverse and sort. The first four return leave the receiver unchanged, but sort operates directly on the receiver. For the sake of consistency, sort should behave like the other Array algorithm methods, returning a sorted array and leaving the receiver unchanged.

Steps to Reproduce:

Run the following in the Swift REPL:

1> var a = [1, 3, 2]
2> a = a.sort(<)
3> a

Expected Results:

$R2: Int[] = size=3 {
  [0] = 1
  [1] = 2
  [2] = 3
}

Actual Results:

Line 2 causes an error:
<REPL>:2:7: error: '()' is not convertible to 'Array<Int>'

Regression:

n/a

Notes:

none

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!