[swift-users] Type inference issue with map and filter chained
mark.lacey at apple.com
Wed Oct 4 11:41:11 CDT 2017
> On Sep 24, 2017, at 1:52 AM, Trevör ANNE DENISE via swift-users <swift-users at swift.org> wrote:
> Hello everyone, I found this on StackOverflow : https://stackoverflow.com/questions/46381752/swift-4-methods-chaining/ <https://stackoverflow.com/questions/46381752/swift-4-methods-chaining/>
> Is this a bug of Swift 4 or is this normal ? I don't understand why the problem only happens when methods are chained !
It’s a bug.
The reason you see this when they are chained is because the type checker (in general) often finds multiple potential solutions (meaning a set of types and particular function overloads) and then has to select the “best” solution from those. For example one solution might involve “map” from type A combined with “filter” from type B, and another might involve “map” from type X and “filter” from type Y.
For the sake of illustration, let’s say it found only those two solutions in your case. Selecting the best solution involves examining the components of the solutions and comparing each component to determine which is best. In your example we may decide A.map is the best map, but Y.filter is the best filter. There is no solution that involves A.map combined with Y.filter, so we consider the solution to be ambiguous.
The combination of the type checker and standard library design should ensure this never happens, but we have some known bugs we need to work through in order to fix all of these cases.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users