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

Update 2

The error given by swiftlang_PONDEROSA-700.1.100.2 is much better than in swiftlang-700.0.52.1 β€” much appreciated, Swift Team! πŸ‘πŸΌπŸ‘πŸΌπŸ‘πŸΌ

/Applications/Xcode-7B60.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift <<-EOF
let initial = (1.0 as Double, 2.0 as Double)
(Array.init as (Double...) -> Array<Double>)(initial as (Double, Double))
EOF
error: libarclite_macosx.a(arclite.o) failed to load objfile for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_macosx.a
Welcome to Apple Swift version 2.0 (700.1.100.2 700.1.74). Type :help for assistance.
initial: (Double, Double) = {
  0 = 1
  1 = 2
}
repl.swift:2:54: error: cannot convert value of type '(Double, Double)' to expected argument type '[Double]'
(Array.init as (Double...) -> Array<Double>)(initial as (Double, Double))
                                             ~~~~~~~~^~~~~~~~~~~~~~~~~~~

Still, the first code block seems like it should compile and return the expected outcome, especially because the following does:

/Applications/Xcode-7B60.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift <<-EOF
(Array.init as (Double...) -> Array<Double>)(1.0, 2.0)
EOF

Thanks for all the hard work!

Update

/Applications/Xcode-7A176x.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift <<-EOF
let initial = (1.0 as Double, 2.0 as Double)
(Array.init as (Double...) -> Array<Double>)(initial as (Double, Double))
EOF

Outputs:

Welcome to Apple Swift version 2.0 (700.0.52.1 700.0.65). Type :help for assistance.
initial: (Double, Double) = {
  0 = 1
  1 = 2
}
repl.swift:2:46: error: cannot invoke value of type '(Double...) -> Array<Double>' with argument list '(Double, Double)'
(Array.init as (Double...) -> Array<Double>)(initial as (Double, Double))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^

So, thankfully, the nonsensical trailing closure error is gone, but shouldn't that invocation work? Ideally, the expected output would be:

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
}

Also, tried:

/Applications/Xcode-7A176x.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift <<-EOF
let initial = (1.0 as Double, 2.0 as Double)
(Array.init as (Double...) -> Array<Double>)(initial as (Double...))
EOF
Welcome to Apple Swift version 2.0 (700.0.52.1 700.0.65). Type :help for assistance.
initial: (Double, Double) = {
  0 = 1
  1 = 2
}
repl.swift:2:64: error: cannot create a variadic tuple
(Array.init as (Double...) -> Array<Double>)(initial as (Double...))
                                                               ^
repl.swift:2:54: error: '(Double, Double)' is not convertible to '(Double)'
(Array.init as (Double...) -> Array<Double>)(initial as (Double...))
                                             ~~~~~~~~^~~~~~~~~~~~~~

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!