Swift: Can’t get reference to constructor functions

Originator:rix.rob
Number:rdar://19091008 Date Originated:27-Nov-2014 03:12 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.1.1 (6A2006)
Classification:Other Bug Reproducible:Always
 
Summary:
Constructors are functions. Static functions are also functions. The difference is that the latter can be passed as the argument to map, but the former cannot.


Steps to Reproduce:
1. Try to run this code:
struct S {
	init(Int) {}
}
let f: Int -> S = S
let x: [S] = map([1, 2, 3], S.init)


Expected Results:
I expected this to compile, and for f or at least x to be successfully bound by those expressions.


Actual Results:
Both of them error: “expected member name or constructor call after type name” and “initializer cannot be referenced without arguments” respectively.


Regression:
The workaround is to construct an anonymous closure:

let x = map([1, 2, 3]) { S($0) }


Notes:
This makes for a proliferation of static functions or free functions constructing types which could otherwise just be using the extant initializers/constructors. I would much rather see:

map(array, Result) // or equivalently Result.init

than

map(array) { Result($0) }

More generally, improving Swift’s support for tacit programming[1] would be lovely ❤️

1: http://en.wikipedia.org/wiki/Tacit_programming

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!