Swift: Bad error message with nested function & closures yada yada
| Originator: | rix.rob | ||
| Number: | rdar://19153042 | Date Originated: | 04-Dec-2014 11:51 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.1.1 (6A2006) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
Nested local functions mustn’t reference themselves, which is terrible, but at least the error is clear. Certain references within closures give a misleading/flat out wrong error, too.
Steps to Reproduce:
1. This code. Compile it.
func f(x: Int?) {
func g() {
x.map { _ in
g
}
}
}
Expected Results:
I expected it to bother me about the expression evaluating to an unused closure, or at least to error about the recursive reference.
Actual Results:
./spurious-local-nested-function-error-of-doom.swift:6:4: error: cannot reference a local function with captures from another local function
WAT
Regression:
N/A
Notes:
I found two (count ’em!) sweet crashes trying to reduce this:
1. rdar://19152922
2. rdar://19153007
(Look how small the delta between those numbers is!)
I assume it’s referring to the closure passed to map, but _who knows_! The diagnostic points at the inner reference to g. At least the “local functions cannot reference themselves” error message would point me at the actual problem :\
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!