Shorthand Array and Dictionary syntax in Swift doesn't support closures

Originator:timbogeld
Number:rdar://19175346 Date Originated:08-Dec-2014
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification: Reproducible:Always
 
Summary:
In Swift Array<() -> ()>() can be used to initialise an empty array of closures that take no input and return nothing.

The Swift Programming Language Guide claims that "the two forms are functionally identical" and says that "the shorthand form is preferred".

However, when trying to create an array of closures, only the longer syntax variant is accepted by the compiler.
The same applies to dictionaries that involve closures.

Steps to Reproduce:
Create a playground with following content:

import UIKit

// Creating an array and dictionary of/with closures:
var arrayOfClosures = Array<() -> ()>()
var dictionaryWithClosures = Dictionary<String, () -> ()>()

// Should be functionally identical:
var arrayOfClosures2 = [() -> ()]()
var dictionaryWithClosures2 = [String, () -> ()]()

Expected Results:
The playground should compile without errors.

[() -> ()]() should have the same behaviour as Array<() -> ()>()
[String, () -> ()]() should have the same behaviour as Dictionary<String, () -> ()>()

Actual Results:
The usage of [() -> ()]() or [String, () -> ()]() throws errors.

Version:
Xcode Version 6.1.1 (6A2008a)

Notes:


Configuration:
N/A

Attachments:
'ArrayClosureBug.playground.zip' was successfully uploaded.

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!