Swift: Can’t get reference to enum constructor functions
| Originator: | rix.rob | ||
| Number: | rdar://19091028 | Date Originated: | 27-Nov-2014 03:20 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.1.1 (6A2006) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
Like with rdar://19091008 and initializers, enum cases are functions but you can’t get reference to them.
Steps to Reproduce:
1. Try to compile this:
enum E {
case C(Int)
}
let f: Int -> E = E.C
let x: [E] = map([1, 2, 3], E.C)
Expected Results:
I expected it to compile and for f to be bound to the .C constructor and x to an array of type E constructed with the integers being mapped over.
Actual Results:
The compiler errors.
Regression:
Once again, { E.C($0) } works, but is undesirable.
Notes:
The compiler actually gives a specific error for this:
error: partial application of enum constructor is not allowed
However, I haven’t the foggiest why this would constitute partial application. Are enum cases curried? What argument has been applied? This isn’t an instance method; is the _type_ getting passed into the function? That seems weird.
Either way, Swift’s support for tacit programming[1] would be improved by this.
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!