Swift 2b3: Incongruous `unexpected trailing closure` error in `init` function which is cast and called without trailing closure.
| Originator: | jdhealy | ||
| Number: | rdar://21784170 | Date Originated: | 12-Jul-2015 12:17 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | /Applications/Xcode-7A152u.app |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
Incongruous `unexpected trailing closure` error in `init` function which is cast and called without (trailing or non-trailing) closure.
Steps to Reproduce:
- Paste into command line:
```
swift <<-EOF
let initial = (1.0 as Double, 2.0 as Double)
(Array.init as (Double...) -> Array<Double>)(initial as (Double, Double))
EOF
```
Expected Results:
```
Welcome to Apple Swift version 2.0 (700.0.45 700.0.57.2). Type :help for assistance.
initial: (Double, Double) = {
0 = 1
1 = 2
}
$R0: [Double] = 2 values {
[0] = 1
[1] = 2
}
```
Actual Results:
```
Welcome to Apple Swift version 2.0 (700.0.45 700.0.57.2). Type :help for assistance.
initial: (Double, Double) = {
0 = 1
1 = 2
}
repl.swift:2:13: error: unexpected trailing closure
(Array.init as (Double...) -> Array<Double>)(initial as (Double, Double))
^
```
Notes:
The following code block compiles and produces the expected output:
```
swift <<-EOF
let initial = (1.0 as Double, 2.0 as Double)
(Array.init as (Double...) -> Array<Double>)(1.0, 2.0)
EOF
```
The following two code blocks fail with the same `repl.swift:2:13: error: unexpected trailing closure` error as the topmost code block:
```
swift <<-EOF
let initial = (1.0 as Double, 2.0 as Double)
(Array.init as (Double...) -> Array<Double>)(initial)
EOF
```
```
swift <<-EOF
let initial = (1.0 as Double, 2.0 as Double)
(Array.init as (Double...) -> Array<Double>)(
Optional(
initial as (Double, Double)
)!
)
EOF
```
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!
Update 2
The error given by
swiftlang_PONDEROSA-700.1.100.2is much better than inswiftlang-700.0.52.1β much appreciated, Swift Team! ππΌππΌππΌStill, the first code block seems like it should compile and return the expected outcome, especially because the following does:
Thanks for all the hard work!
Update
Outputs:
So, thankfully, the nonsensical trailing closure error is gone, but shouldn't that invocation work? Ideally, the expected output would be:
Also, tried: