Misleading error
| Originator: | matteosartori | ||
| Number: | rdar://22453496 | Date Originated: | 27-Aug-2015 12:08 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode Version 7.0 beta 6 (7A192o) |
| Classification: | UI/Usability | Reproducible: | Always |
Summary:
The following code gives a wrong or misleading error
let myArr = [[1, 2, 3, 4],[1, 2, 4, 8],[2, 3, 5, 7]]
let output = myArr.flatMap { value in
print("value is ", value)
return value
}
print("output: ), output)
Steps to Reproduce:
Enter the above code in a Playground.
Expected Results:
I expected the output to be
value is [1, 2, 3, 4]
value is [1, 2, 4, 8]
value is [2, 3, 5, 7]
output: [1, 2, 3, 4, 1, 2, 4, 8, 2, 3, 5, 7]
Actual Results:
The above code produces the error
Playground execution failed: /var/folders/cl/d10fdkcx7kv5bjgrfg8x3gy40000gn/T/./lldb/12716/playground486.swift:27:20: error: cannot invoke 'flatMap' with an argument list of type '((_) -> _)'
let output = myArr.flatMap { value in
^
/var/folders/cl/d10fdkcx7kv5bjgrfg8x3gy40000gn/T/./lldb/12716/playground486.swift:27:20: note: overloads for 'flatMap' exist with these partially matching parameter lists: ((Self.Generator.Element) throws -> S), (@noescape (Self.Generator.Element) throws -> T?)
let output = myArr.flatMap { value in
Regression:
This happens in all configurations.
Notes:
Commenting out the `return value` line causes the code to be correctly interpreted and prints the expected values.
Commenting out the `print("value is ",value)` line also causes the code to be correctly interpreted and produces the expected output.
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!