Xcode 6.3 (6D554n): [Swift] Swift compiler fails to parse '[() -> ()]()' correctly
| Originator: | janoschhildebrand | ||
| Number: | rdar://20305739 | Date Originated: | 26-Mar-2015 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.3 (6D554n) |
| Classification: | Other Bug | Reproducible: | Always |
Summary: The Swift compiler currently seems unable to make sense of the following statement which should create a new array of functions of type () -> (): var array = [() -> ()]() Using Xcode 6.3b4 I get the following three errors: * Expected ',' separator * Expected expression in container literal * Consecutive statements on a line must be separated by ';' As Void is a typealias to (), the following unsurprisingly produces the same errors: var array = [Void -> Void]() Interestingly, SourceKitService on the other hand seems to accept the statement but deduces the type of the resulting array as '[()]'. The following approaches work fine however and can be used as workarounds: var blocks2: [() -> ()] = Array() var blocks3 = Array<() -> ()>() Steps to Reproduce: 1. Open the attached Xcode project and build 2. The compiler should report the mentioned errors 3. Alt-click on 'blocks' to see the SourceKitService type deduction Expected Results: I would expect this form of creating such an array to be valid and accepted by the compiler and produce the same result as the presented workarounds. Actual Results: The compiler fails to parse the given expression. Version: Xcode 6.3 (6D554n) Apple Swift version 1.2 (swiftlang-602.0.47.4 clang-602.0.48) 10.10.2 (14C1514) Notes: Potentially related to rdar://19812302 which is another case of the compiler having troubles with complex type constructs inside literals.
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!