You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
The following code compiles without a warning, even though the `compactMap()` is arguably a mistake and should be replaced by `map()`:
structItem {
var text: String
}
let items = [Item(text: "foo")]
let filteredItems = items.compactMap { $0.text }
But if I replace the last line with:
let filteredItems = items.compactMap(\.text)
It fails with:
Generic parameter 'ElementOfResult' could not be inferred
Key path value type 'String' cannot be converted to contextual type 'ElementOfResult?'
I'm not sure whether the better fix here would be for `compactMap { $0.text }` to produce a warning, or for `compactMap(.text)` to silently succeed, but it definitely seems wrong that these aren't consistent.
The text was updated successfully, but these errors were encountered:
Environment
Xcode 11.6, Swift 5.2
Additional Detail from JIRA
md5: 0300b2587bde2e6fea9e7b74b21a2d20
Issue Description:
The following code compiles without a warning, even though the `compactMap()` is arguably a mistake and should be replaced by `map()`:
But if I replace the last line with:
It fails with:
I'm not sure whether the better fix here would be for `compactMap { $0.text }` to produce a warning, or for `compactMap(.text)` to silently succeed, but it definitely seems wrong that these aren't consistent.
The text was updated successfully, but these errors were encountered: