`Substring.count` is ambiguous inside a `[Substring].filter` block [Swift 5][Xcode 10P107d]

Originator:misacek
Number:rdar://48722421 Date Originated:March 8 2019, 9:51 PM
Status: Resolved:
Product:Xcode 10.2 / Swift 5 Product Version:
Classification: Reproducible:Always
 
Summary:
I've created a simple Playground code demonstrating the issue.

Having a string, for example:
"abc def ghi jklmno"

When attempting to call a split – filter – join chain, like:

"abc def ghi jklmno"
.split(separator: " ")
.filter({(substr) -> Bool in return substr.count == 3})
.joined(separator: ", ")

Swift 5 fails to compile the code, stating use of `count` as ambiguous.

Weird behaviours:

• When using an intermediate variable after `split` (thus breaking into two parts — let a = "…".split(…); a.filter(…).joined(…)), compilation succeeds with a correct output.

• When invoking the `substr` block variable before calling `substr.count` (even by putting it on a separate line to only be printed in the variable pane in the Playgrounds), the compilation succeeds with a correct output — acts as a work-around.

• When omitting the `.joined` operation, the compilation succeeds, but `.filter` block incorrectly outputs a result of [[Character]] ( [["a","b","c"], ["d"… ) instead of correct [Substring] ( ["abc","def",… ).

Steps to Reproduce:
See the attached Playground code.

Version/Build:
Xcode 10.2 Beta 4 (10P107d)

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!